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

MapSwift - lesson 10

leveton
June 07, 2017
30

MapSwift - lesson 10

leveton

June 07, 2017
Tweet

Transcript

  1. preventing retain cycles A weak pointer will hold a reference

    to another object but will not increase its retain count
  2. Basic networking to get locations from a server We use

    3 objects NSMutableURLRequest, URLSession, and URLSessionDataTask to get data from a server. Like other managers we’ve used, they’re just subclasses of NSObject but with extra properties and methods to facilitate interactive with a remote server.
  3. AFNetworking Using URL, NSMutableURLRequest, URLSession, and URLSessionDataTask by themselves, while

    powerful, are missing features that a full-fledged, network-based application may need. Many companies and indie developers use the AFNetworking 3rd-party library which uses these objects under the hood.
  4. GCD - Grand Central Dispatch GCD facilitates multi-threading by abstracting

    away the hard parts. Things like locking to avoid race conditions. Inside the network block, we wrap ‘layoutMapWithData’ so that it’s executed on the main thread.
  5. GCD - Grand Central Dispatch What’s happening here is we

    are asking the system’s runtime to asynchronously run some process on the main thread. We want it done asynchronously so that it occurs without interfering with the current process (in this case downloading from a webservice). Under the hood, this DispatchQueue is done serially - the code in the block is performed in order and not at the same time.
  6. GCD - Grand Central Dispatch What happens if we remove

    the call to DispatchQueue.main.async in layoutMapWithDictionary? Try it and you’ll find that the map is no longer annotated with pins. (Jerk the map a little and the pins appear because MapKit reloads with a full datasource).
  7. GCD - Grand Central Dispatch By calling DispatchQueue.main asynchronously and

    sending it a block of code to execute, we can “force” the UI to be responsive. This is critical for user experience.