Skip to content

Instantly share code, notes, and snippets.

View vialyx's full-sized avatar
🎯
Focusing

Maxim Vialyx vialyx

🎯
Focusing
View GitHub Profile
typealias DownloadResult = (items: [String], error: Error?)
func load() -> DownloadResult {
func dowload() -> DownloadResult {
return (["Zips"], nil)
}
let nestedFunction = dowload()
return nestedFunction
/*
{ (parameters) -> return type in
statements
}
*/
let BoolClosure: (Bool) -> Void = { parameter in
print("\(parameter)")
}
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)
*/
/*
/* 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
final class Model {
func load(completion: @escaping ([String]) -> Void) {
// statement
}
}
final class ViewController: UIViewController {
func patch(user: @autoclosure () -> User) {
// statement
}
patch(user: "Maxim")
patch { "Mike" }
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: "")
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")
@IBInspectable
var activeSegmentColor: UIColor = .segmentActiveBackground
@IBInspectable
var textColor: UIColor = .segmentText
@IBInspectable
var activeTextColor: UIColor = .segmentActiveText
enum EmailValidationError {
// TODO: - Cases
case empty
// TODO: - Cases can be declared on a single line
case noDomain, invalid
}