Skip to content

Instantly share code, notes, and snippets.

View yarneo's full-sized avatar
💭
I may be slow to respond.

Yarden Eitan yarneo

💭
I may be slow to respond.
View GitHub Profile
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”
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")
enum Person {
case FullName(String)
case personID(Int)
init(personID: Int) {
if personID == 123456789 {
self = .FullName(“Barack Obama”)
} else {
self = .personID(personID)
}
}
func calculateCircle(radius : Double) ->
(area : Double, circumference : Double, diameter : Double) {
return (M_PI * pow(radius, 2), 2 * M_PI * radius, 2 * radius)
}
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"
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];