Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

KEITH SMILEY

Slide 3

Slide 3 text

SWIFT THINKING

Slide 4

Slide 4 text

==(LHS: YOLO)

Slide 5

Slide 5 text

view1.al_left == view2.al_right

Slide 6

Slide 6 text

NSLayoutConstraint(item: view1, attribute: NSLayoutAttribute.Left, relatedBy: NSLayoutRelation.Equal, toItem: view2, attribute: NSLayoutAttribute.Right ...

Slide 7

Slide 7 text

operator infix .... {} @infix func .... (lhs: Int, rhs: Int) -> Range { return Range(start: Int(arc4random_uniform(UInt32(lhs))), end: Int(arc4random_uniform(UInt32(rhs)))) }

Slide 8

Slide 8 text

for i in 1....5 { println(i) } // Expected: 1 2 3 4 5 // Actual: 1 2 3

Slide 9

Slide 9 text

NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"\\w+" options:0 error:nil]; NSRange range = NSMakeRange(0, string.length) NSUInteger numberOfMatches = [regex numberOfMatchesInString:string options:0 range:range]; if (numberOfMatches > 0) { ... }

Slide 10

Slide 10 text

let regex = NSRegularExpression(pattern: "\\w+", options: nil, error: nil) let range = NSMakeRange(0, countElements(string)) let numberOfMatches = regex.numberOfMatchesInString(string, options: nil, range: range) if numberOfMatches > 0 { ... }

Slide 11

Slide 11 text

if string =~ "\\w+" { ... }

Slide 12

Slide 12 text

-- Haskell matches :: String -> Bool matches x = x =~ "\\w+" # Ruby if string =~ /\w+/ ... end # Shell script... if [[ $string =~ "\w+" ]]; then ... fi

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

// This ~= operator ensures that indexPath.row // is found in the range on the right. if 1...list.count ~= indexPath.row { ... } // Check to see if the key is contained in the array. if ["foo", "bar"] ~= key { ... }

Slide 15

Slide 15 text

date - 2.days() - 1.hour() + 5.minutes()

Slide 16

Slide 16 text

isEqualToString:

Slide 17

Slide 17 text

[thing1 isEqual:thing2];

Slide 18

Slide 18 text

thing1 == thing2

Slide 19

Slide 19 text

{ "user": { "username": "Keith", "id": 1 } }

Slide 20

Slide 20 text

id JSON = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error]; NSDictionary *userDict = JSON[@"user"];

Slide 21

Slide 21 text

for (NSDictionary *userDict in JSON) { NSLog(@"%@", userDict[@"username"]); }

Slide 22

Slide 22 text

let JSON: AnyObject = NSJSONSerialization .JSONObjectWithData(data, options: nil, error: &error)

Slide 23

Slide 23 text

if let userDict = JSON as? NSDictionary { if let username = userDict.objectForKey("username") as? String { println(username) } }

Slide 24

Slide 24 text

if let users = JSON as? NSDictionary[] { for userDict in users { if let username = userDict.objectForKey("username") as? String { println(username) } } }

Slide 25

Slide 25 text

if let repos = githubJSON as? NSDictionary[] { for repoDict in repos { if let permissions = repoDict.objectForKey("permissions") as? NSDictionary { if let isAdmin = permissions.objectForKey("admin") as? Bool { if isAdmin { println("They are an admin!") } } } } }

Slide 26

Slide 26 text

if let isAdmin = repoDict["permissions"]?["admin"]?.bool! { if isAdmin { println("They are an admin!") } }

Slide 27

Slide 27 text

if let isAdmin = repoDict["permissions"]["admin"].bool { if isAdmin { println("They are an admin!") } }

Slide 28

Slide 28 text

type User struct { Username string `json:"username"` } var user User err = json.Unmarshal(JSON, &user)

Slide 29

Slide 29 text

data User = User { username :: String , userID :: Integer } deriving (Show) instance FromJSON User where parseJSON (Object j) = User <$> (j .: "username") <*> (j .:? "id") case decode JSON :: Maybe User of Just user -> print user Nothing -> error "Invalid JSON"

Slide 30

Slide 30 text

BEER