Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Cocoa is the new Carbon: The Future of Apple’s Beloved Framework

Cocoa is the new Carbon: The Future of Apple’s Beloved Framework

In this talk, Adrian provides lots of speculation and highly arguable unverified gossip, about how the design of Swift will lead Apple to redesign Cocoa into new directions, and maybe replacing it altogether. Some code examples will help him defend a point that nobody outside of Cupertino can sustain for sure.

Presentation given in Zürich, Switzerland, February 26th, 2015.

The speech of the presentation can be found here:
https://akos.ma/blog/cocoa-is-the-new-carbon-the-future-of-apples-beloved-framework/

Adrian Kosmaczewski

February 26, 2015
Tweet

More Decks by Adrian Kosmaczewski

Other Decks in Technology

Transcript

  1. 8 bit → 16 bit → 32 bit → 64

    bit © akosma 2015 8
  2. Integer Basic → Object Pascal & MacApp → C++ &

    Metrowerks PowerPlant → Objective-C & Cocoa → Swift & Standard Library © akosma 2015 9
  3. Carbon Deprecated in OS X 10.8 "Mountain Lion" 2000 -

    2012 #if __i386__ #include <Carbon/Carbon.h> #else #include <Carbon.h> #endif © akosma 2015 17
  4. 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
  5. Objective-C 2.0 (2/2) 2006 - now // After @interface SomeClass

    @property (nonatomic, strong) NSObject *stuff; @end © akosma 2015 22
  6. Cocoa 1988 - now Deprecated in 5… 4… 3… !

    @import Cocoa; © akosma 2015 24
  7. 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
  8. 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
  9. LINQ (1/2) public void linq() { List<Product> 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
  10. 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
  11. 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
  12. 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
  13. Notification Center (1/3) struct Notification<A> { let name: String }

    func postNotification<A>(note: Notification<A>, value: A) { let userInfo = ["value": Box(value)] let center = NSNotificationCenter.defaultCenter() center.postNotificationName(note.name, object: nil, userInfo: userInfo) } © akosma 2015 46
  14. Notification Center (2/3) class NotificationObserver { let observer: NSObjectProtocol init(notification:

    Notification<A>, block aBlock: A -> ()) { let center = NSNotificationCenter.defaultCenter() observer = center.addObserverForName(notification.name, object: nil, queue: nil) { note in if let value = (note.userInfo?["value"] as? Box<A>)?.unbox { aBlock(value) } } } deinit { … } } © akosma 2015 47
  15. Notification Center (3/3) let notif: Notification<NSError> = 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
  16. Events (1/2) class Event<T> { 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
  17. Events (2/2) let event = Event<Void>() 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
  18. 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
  19. 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
  20. 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