import UIKit.UIFont
protocol FontConvertible {
func font(size: CGFloat) -> UIFont
}
extension FontConvertible where Self: RawRepresentable, Self.RawValue == String {
func font(size: CGFloat) -> UIFont {
return UIFont(font: self, size: size)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum NetworkResponse { | |
case response(URLResponse, Data) | |
case error(Error) | |
} | |
func processRequestResponse(_ response: NetworkResponse) { | |
guard | |
case let .response(urlResp, data) = response, | |
let httpResp = urlResp as? HTTPURLResponse, | |
200..<300 ~= httpResp.statusCode |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
////////////////////////////////// | |
enum Media { | |
case book(title: String, author: String, year: Int) | |
case movie(title: String, director: String, year: Int) | |
case website(urlString: String) | |
} | |
let m = Media.movie(title: "Captain America: Civil War", director: "Russo Brothers", year: 2016) | |
if case let Media.movie(title, _, _) = m { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
////////////////////////////////// | |
if case 200 ... 299 = statusCode { | |
// do something | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
extension UIStoryboard { | |
/// Main storyboard | |
public var main: UIStoryboard { | |
return UIStoryboard(name: "Main", bundle: nil) | |
} | |
/// Instantiates and returns the view controller with the specified identifier. | |
/// | |
/// - Parameter identifier: uniquely identifies equals to Class name |