Slide 1

Slide 1 text

Cocoa is the new Carbon The Future of Apple’s Beloved Framework © akosma 2015 1

Slide 2

Slide 2 text

Adrian Kosmaczewski @akosma https://github.com/akosma © akosma 2015 2

Slide 3

Slide 3 text

“Everything changes and nothing stands still.” Heraclitus of Ephesus, (535 - 475 BC) © akosma 2015 3

Slide 4

Slide 4 text

“Πάντα χωρεῖ καὶ οὐδὲν μένει” Ἡράκλειτος © akosma 2015 4

Slide 5

Slide 5 text

© akosma 2015 5

Slide 6

Slide 6 text

© akosma 2015 6

Slide 7

Slide 7 text

6502 → 68000 → PowerPC → Intel → ARM © akosma 2015 7

Slide 8

Slide 8 text

8 bit → 16 bit → 32 bit → 64 bit © akosma 2015 8

Slide 9

Slide 9 text

Integer Basic → Object Pascal & MacApp → C++ & Metrowerks PowerPlant → Objective-C & Cocoa → Swift & Standard Library © akosma 2015 9

Slide 10

Slide 10 text

Procedural → Object Oriented → Functional © akosma 2015 10

Slide 11

Slide 11 text

“"Plus ça change, plus c'est la même chose."” Jean-Baptiste Alphonse Karr (1808 - 1890) © akosma 2015 11

Slide 12

Slide 12 text

Heraclitus ! Jean-Baptiste © akosma 2015 12

Slide 13

Slide 13 text

Transitional Technologies © akosma 2015 13

Slide 14

Slide 14 text

Mac 68k Emulator 1992 - 2008 (!) © akosma 2015 14

Slide 15

Slide 15 text

Macintosh Application Environment 1994 - 1998 © akosma 2015 15

Slide 16

Slide 16 text

Classic Environment Deprecated in OS X 10.5 "Leopard" 2000 - 2008 © akosma 2015 16

Slide 17

Slide 17 text

Carbon Deprecated in OS X 10.8 "Mountain Lion" 2000 - 2012 #if __i386__ #include #else #include #endif © akosma 2015 17

Slide 18

Slide 18 text

The LLVM Compiler Infrastructure 2003 - now © akosma 2015 18

Slide 19

Slide 19 text

Rosetta Deprecated in OS X 10.7 "Lion" 2006 - 2011 © akosma 2015 19

Slide 20

Slide 20 text

Universal Binaries © akosma 2015 20

Slide 21

Slide 21 text

Objective-C 2.0 (1/2) 2006 - now // Before @implementation SomeClass - (NSObject *)stuff { return _stuff; } - (void)setStuff:(NSObject *)newStuff { [newStuff retain]; [_stuff release]; _stuff = newStuff; } @end © akosma 2015 21

Slide 22

Slide 22 text

Objective-C 2.0 (2/2) 2006 - now // After @interface SomeClass @property (nonatomic, strong) NSObject *stuff; @end © akosma 2015 22

Slide 23

Slide 23 text

LLVM Around 2009 → Xcode Static Analyzer → Automatic Resource Counting (ARC) © akosma 2015 23

Slide 24

Slide 24 text

Cocoa 1988 - now Deprecated in 5… 4… 3… ! @import Cocoa; © akosma 2015 24

Slide 25

Slide 25 text

nullable Objective-C Pointers 1 ! @interface LocationDataController : NSObject @property (nonnull, nonatomic) NSArray *locations; @property (nullable, nonatomic) Location *latestLocation; - (void)addPhoto:(nonnull Photo *)photo forLocation:(nonnull Location *)location; - (nullable Photo *)photoForLocation:(nonnull Location *)location; @end 1 "Swift 1.2" by Nate Cook © akosma 2015 25

Slide 26

Slide 26 text

Cocoa should remain for backwards compatibility during 10 years at least, until 2025! © akosma 2015 26

Slide 27

Slide 27 text

© akosma 2015 27

Slide 28

Slide 28 text

What is Swift? © akosma 2015 28

Slide 29

Slide 29 text

Modern Safe Fast Interoperable © akosma 2015 29

Slide 30

Slide 30 text

© akosma 2015 30

Slide 31

Slide 31 text

Features © akosma 2015 31

Slide 32

Slide 32 text

Protocols, Pattern Matching Generics, Tuples, Optionals, Enums Strong Typing, Type Inference Structs, Functions © akosma 2015 32

Slide 33

Slide 33 text

OOP features of Swift are based in Functional primitives and mechanisms! © akosma 2015 33

Slide 34

Slide 34 text

Inspiration © akosma 2015 34

Slide 35

Slide 35 text

C#, JavaScript, Haskell, Erlang, Ruby, C++, Java, Scala © akosma 2015 35

Slide 36

Slide 36 text

© akosma 2015 36

Slide 37

Slide 37 text

How would the successor of Cocoa look like? © akosma 2015 37

Slide 38

Slide 38 text

Gedankenexperiment ! © akosma 2015 38

Slide 39

Slide 39 text

© akosma 2015 39

Slide 40

Slide 40 text

Swift Standard Library let array = [10, 200, 3000] for (pos, value) in enumerate(array) { println("\(pos): \(value)") } // 0: 10 // 1: 200 // 2: 3000 © akosma 2015 40

Slide 41

Slide 41 text

LINQ (1/2) public void linq() { List products = GetProductList(); var expensive = from p in products where p.Stock > 0 && p.Price > 1000 select p; foreach (var product in expensive) { Console.WriteLine(product.Name); } } © akosma 2015 41

Slide 42

Slide 42 text

LINQ (2/2) func linq(){ let products = productsList() let expensive = products .find { p in p.stock > 0 && p.price > 1000 } for p in expensive { println(p.name) } } © akosma 2015 42

Slide 43

Slide 43 text

© akosma 2015 43

Slide 44

Slide 44 text

Dollar.swift let double = { (params: Int...) -> [Int] in return $.map(params) { $0 * 2 } } let subtractTen = { (params: Int...) -> [Int] in return $.map(params) { $0 - 10 } } let doubleSubtractTen = $.compose(double, subtractTen) doubleSubtractTen(5, 6, 7) => [0, 2, 4] © akosma 2015 44

Slide 45

Slide 45 text

Alamofire let user = "user" let password = "password" Alamofire.request(.GET, "http://somewhere.over/the.rainbow") .authenticate(user: user, password: password) .validate(statusCode: 200..<300) .responseString { (_, _, string, _) in println(string) } .responseJSON { (_, _, JSON, _) in println(JSON) } © akosma 2015 45

Slide 48

Slide 48 text

Notification Center (3/3) let notif: Notification = Notification(name: "Global panic") let myError: NSError = NSError(domain: "io.objc.sample", code: 42, userInfo: [:]) postNotification(notif, myError) let observer = NotificationObserver(notification: notif) { err in println(err.localizedDescription) } © akosma 2015 48

Slide 49

Slide 49 text

Events (1/2) class Event { typealias EventHandler = T -> () private var eventHandlers = [EventHandler]() func addHandler(handler: EventHandler) { eventHandlers.append(handler) } func raise(data: T) { for handler in eventHandlers { handler(data) } } } © akosma 2015 49

Slide 50

Slide 50 text

Events (2/2) let event = Event() event.addHandler { println("Hello") } event.addHandler { println("World") } event.raise() // What? let event = Event<(String, String)>() event.addHandler { a, b in println("Hello \(a), \(b)") } event.raise("First", "Second") © akosma 2015 50

Slide 51

Slide 51 text

SwiftyUserDefaults Defaults["color"] = "red" Defaults["launchCount"] = 0 Defaults["color"] ?= "white" Defaults["firstLaunchAt"].date // returns NSDate? Defaults["launchCount"] += 1 if !Defaults.hasKey("hotkey") { Defaults.remove("hotkeyOptions") } © akosma 2015 51

Slide 52

Slide 52 text

SwiftMoment let today = moment() let before = moment("2015-01-19") let earlier = before < today // true let soon = today + 1.hours let duration = 5.hours + 56.minutes let format = "EE yyyy/dd MMMM HH:mm" let birthday = moment("Tue 1973/4 September 12:30", format)! let str = birthday.format(dateFormat: "EE QQQQ yyyy/dd/MMMM") // "Tue 3rd quarter 1973/04/September" © akosma 2015 52

Slide 53

Slide 53 text

Are we there yet? Hint: no. © akosma 2015 53

Slide 54

Slide 54 text

Protocols, Pattern Matching Generics, Tuples, Optionals, Enums Strong Typing, Type Inference Structs, Functions © akosma 2015 54

Slide 55

Slide 55 text

Functions and structs instead of objects and classes © akosma 2015 55

Slide 56

Slide 56 text

Not all is OK What about reflection? Documentation? UI? © akosma 2015 56

Slide 57

Slide 57 text

Time will tell ! © akosma 2015 57

Slide 58

Slide 58 text

Thanks! ! © akosma 2015 58

Slide 59

Slide 59 text

Adrian Kosmaczewski @akosma https://github.com/akosma © akosma 2015 59

Slide 60

Slide 60 text

Special thanks to Junior Bontognali @bontojr for the organisation Fabrice Truillot de Chambrier @fabricetdc And the great people I follow on Twitter © akosma 2015 60

Slide 61

Slide 61 text

Slides created with Deckset © akosma 2015 61