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 bouncerResponse(job: String, age: Int, bribe: Int) -> String? { | |
switch (job, age, bribe) { | |
case (let j, _, _) where (j.rangeOfString(“model”) != nil) : | |
return “come in, welcome, the VIP is that way :)” | |
case (_, 0..<21, _): return “too young bro” | |
case (“Owner of OMNIA”, 32, _): | |
return “sorry, we don’t let our competitors in” |
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
struct Dog { | |
var name: String | |
var type: String | |
init(name: String, type: String) { | |
self.name = name | |
self.type = type | |
} | |
} | |
var aDog = Dog(name: "Bugsy", type: "Pug") |
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 Person { | |
case FullName(String) | |
case personID(Int) | |
init(personID: Int) { | |
if personID == 123456789 { | |
self = .FullName(“Barack Obama”) | |
} else { | |
self = .personID(personID) | |
} | |
} |
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 calculateCircle(radius : Double) -> | |
(area : Double, circumference : Double, diameter : Double) { | |
return (M_PI * pow(radius, 2), 2 * M_PI * radius, 2 * radius) | |
} |
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
protocol Summable { func +(lhs: Self, rhs: Self) -> Self } | |
extension Int: Summable {} | |
extension Double: Summable {} | |
extension String: Summable {} | |
func sum<T: Summable>(lhs:T, _ rhs:T) -> T { | |
return lhs + rhs | |
} | |
sum("Hello ", "World") // "Hello World" |
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
NSDictionary *dogBreeds = @{@”Bugsy” : @”Pug”, | |
@”Marcelle” : @”Chow Chow”, | |
@”Daisy” : @”Labrador”; | |
NSString *name = @"Chloe's breed is: "; | |
NSString *breed = dogBreeds[@"Chloe"]; | |
/* Crash at runtime because breed is null */ | |
NSString *message = [name stringByAppendingString:breed]; |
NewerOlder