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.UIColor | |
extension UIColor { | |
static let common = UIColor(hex: "#B11835") | |
static let commonText = UIColor(hex: "#114747") | |
static let commonActionBackground = UIColor(hex: "#119C84") | |
static let commonActionText = UIColor(hex: "#110808") | |
static let positive = UIColor(hex: "#11C7C1") | |
static let negative = UIColor(hex: "#118475") |
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.UIColor | |
extension UIColor { | |
convenience init(hex: String) { | |
// Initializer supports work with formatts: "#FFFFFF", "FFFFFF" | |
let cString: String = hex.trimmingCharacters(in: .whitespacesAndNewlines) | |
.uppercased() | |
.replacingOccurrences(of: "#", with: "") | |
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
func patch(user: @autoclosure () -> User) { | |
// statement | |
} | |
patch(user: "Maxim") | |
patch { "Mike" } |
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
final class Model { | |
func load(completion: @escaping ([String]) -> Void) { | |
// statement | |
} | |
} | |
final class ViewController: UIViewController { | |
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
/* The animate function | |
UIView.animate(withDuration: TimeInterval, animations: () -> Void) | |
*/ | |
// Can be | |
UIView.animate(withDuration: 0.25, animations: { (_) in | |
}) | |
// Simpler, just use trailing | |
UIView.animate(withDuration: 0.25) { | |
// statement |
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
let integers = [1, 2, 3, 4, 5] | |
/* | |
Inferring Type From Context | |
Compile already know the result is String array | |
*/ | |
/* | |
Implicit Returns from Single-Expression Closures | |
Just String($0) | |
*/ | |
/* |
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
/* | |
{ (parameters) -> return type in | |
statements | |
} | |
*/ | |
let BoolClosure: (Bool) -> Void = { parameter in | |
print("\(parameter)") | |
} |
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
typealias DownloadResult = (items: [String], error: Error?) | |
func load() -> DownloadResult { | |
func dowload() -> DownloadResult { | |
return (["Zips"], nil) | |
} | |
let nestedFunction = dowload() | |
return nestedFunction |
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
typealias User = String | |
func getUsers(with ids: UUID...) -> [User] { | |
return ["Maxim", "Nik"] | |
} | |
var downloadTask: (UUID...) -> [String] = getUsers | |
downloadTask(UUID()) |
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
func update(user: inout User) -> Error? { | |
user = "Mike" | |
return nil | |
} |