This file contains 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 Foundation | |
class Product: NSObject { | |
let identifier: Int | |
init(identifier: Int) { | |
self.identifier = identifier | |
super.init() | |
} | |
} |
This file contains 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
/* syntax: | |
public func assert( | |
_ condition: @autoclosure () -> Bool, | |
_ message: @autoclosure () -> String = default, | |
file: StaticString = #file, | |
line: UInt = #line) | |
*/ | |
let minAge = 2 | |
assert(minAge >= 3, "Age did not meet expectation") |
This file contains 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
/* syntax: | |
public func assertionFailure( | |
_ message: @autoclosure () -> String = default, | |
file: StaticString = #file, | |
line: UInt = #line) | |
*/ | |
guard age >= 3 else { | |
return assertionFailure("Age can't be less than 3") | |
} |
This file contains 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
/* syntax: | |
public func precondition( | |
_ condition: @autoclosure () -> Bool, | |
_ message: @autoclosure () -> String = default, | |
file: StaticString = #file, | |
line: UInt = #line) | |
*/ | |
let minAge = 2 | |
precondition(minAge >= 3, "Age did not meet expectation") |
This file contains 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
/* syntax: | |
public func preconditionFailure( | |
_ message: @autoclosure () -> String = default, | |
file: StaticString = #file, | |
line: UInt = #line) -> Never | |
*/ | |
func validateAge(age: Int) -> Bool { | |
guard age >= 3 else { | |
preconditionFailure("Age can't be less than 3") | |
} |
This file contains 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
/* syntax: | |
public func fatalError( | |
_ message: @autoclosure () -> String = default, | |
file: StaticString = #file, | |
line: UInt = #line) -> Never | |
*/ | |
func validateAge(age: Int) -> Bool { | |
guard age >= 3 else { | |
fatalError("Age can't be less than 3") | |
} |
This file contains 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
//: Playground - Closures | |
// Closure take no parameter and return nothing | |
let sayHello: () -> Void = { | |
print("Hello") | |
} | |
sayHello() | |
// Closure take one parameter and return 1 parameter |
This file contains 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 digitsList = [1, 2, 3, 4, 5] | |
let sum = digitsList.reduce(0) { $0 + $1 } | |
print(sum) | |
// prints 15 |
This file contains 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
//: Playground - Closures | |
import Foundation | |
class CaptureList: NSObject { | |
let digit = 5 | |
override init() { | |
super.init() | |
makeSquareOfValue { [digit] squareDigit in |
This file contains 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
//: Playground - Closures | |
import Foundation | |
class CaptureList: NSObject { | |
let digit = 5 | |
typealias onCompletionHandler = (Int) -> Void | |
override init() { | |
super.init() | |