Consistency in an Unpredictable World - Swift Language User Group

Db257e8558247c0658ace420677d5937?s=47 Wendy Lu
January 12, 2017

Consistency in an Unpredictable World - Swift Language User Group

Swift Language User Group 2017

Db257e8558247c0658ace420677d5937?s=128

Wendy Lu

January 12, 2017
Tweet

Transcript

  1. 3.
  2. 4.
  3. 6.
  4. 7.
  5. 8.
  6. 10.
  7. 11.

    "

  8. 13.

    AVPlayer.resetAVAudioSessionCategoryToDefault() FBSDKSettings.configureForUseForApplication(application, withLaunchOptions:launchOptions) GSDAppIndexing.sharedInstance().registerApp(kAppStoreID) iRate.configureForUse() Adjust.appDidLaunch(adjustConfig) Stripe.configureForUse() DDLog.addLogger(DDTTYLogger.sharedInstance()) let fileLogger

    = DDFileLogger() fileLogger.logFileManager.maximumNumberOfLogFiles = 3 DDLog.addLogger(fileLogger) PIDeadlockDetector.enable() PICrash.sharedInstance().configureForUse() PINRemoteImageManager.configureForUse() CBLExperienceManager.configureForUse() NSValueTransformer.setValueTransformer(PIDateValueTransformer(), forName:kPINModelDateValueTransformerKey) CBLDeepLinkManager.sharedManager().configureServicesWithLaunchOp tions(launchOptions)
  9. 18.
  10. 20.
  11. 25.

    let pin = Pin(dictionary:pinJSON) { "board" = { "created_at" =

    "Tue, 13 Aug 2013 16:38:36 +0000"; "id" = 418131215342691718; "name" = "spaces"; }; "comment_count" = 0; "description" = "At the top of my wish list for this fall is a giant chunky knit wool blanket."; "id" = "AVpd31ttshLHlWbcG9g_Kt3uVzZHjfHNvzwT20p6YnO6qzvQnqs_Z5A"; "image_square_url" = "https://s-media-cache-ak0.pinimg.com/b58cc94084407a39d62c83885ce4699e.jpg"; } Pin JSON
  12. 27.

    • imageURL = “https://www.123.com” Pin (Immutable) PinBuilder (Mutable) • title

    = “The best pin in the world” • board = “Cute Cats” • imageURL = “https://www.123.com” • title = • board = “Cute Cats” “The best pin in the world” “Meow”
  13. 30.

    “There are only two hard things in computer science: cache

    invalidation, naming things, and off-by-one errors.”
  14. 32.
  15. 33.
  16. 34.

    Cache "id": "123" Pin123 "id" = "123" "image_url" : "http://new-url.com"

    "recipe" : {"ingredients": ["bananas"]} "imageURL" = "http://old-url.com" "board" = "Cakery" "id" = "123" "image_url" : "http://new-url.com" “board" = "Cakery" "recipe" : {"ingredients": ["bananas"]} Pin JSON
  17. 38.
  18. 40.

    NSNotificationCenter.defaultCenter().addObserverForName("name", object: nil, queue: nil) { note in // ...

    } public func addObserverForName(name: String?, object obj: AnyObject?, queue: NSOperationQueue?, usingBlock block: (NSNotification) -> Void) -> NSObjectProtocol (__NSObserver)
  19. 43.

    class NotificationManager: NSObject { private var observerTokens: [String: AnyObject] =

    [:] deinit { unregisterAll() } func unregisterAll() { for token in observerTokens.values { NSNotificationCenter.defaultCenter().removeObserver(token) } } } http://moreindirection.blogspot.com/2014/08/nsnotificationcenter-swift-and-blocks.html
  20. 48.

    notificationManager.addObserverForUpdatedModel(user, block: { [weak self] notification in if let user

    = notification.object as? PIUser { self?.user = user // Update profile view here! self?.titleLabel.text = user.name self?.imageView.setImageWithURL(user.imageURL) } })