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

MapStack - lesson 2

leveton
March 11, 2016
37

MapStack - lesson 2

leveton

March 11, 2016
Tweet

Transcript

  1. Communicating between objects 3 standard ways to do this 1)

    Sending a message to a property’s method 2) Using NSNotificationCenter to broadcast 3) Using delegate methods to respond to events Let’s review all 3…
  2. NSNotification and NSNotificationCenter NSNotification - encapsulates information so that it

    can be broadcast by an NSNoticationCenter object. NSNoticiationCenter - broadcasts info to your entire program. Uses a linked list of observers under the hood.
  3. NSUserDefaults An in-memory key-value database that persists even when the

    user clears the cache or updates your app. Uses a singleton design pattern under the hood.
  4. NSUserDefaults Only certain objects can be saved to the defaults

    dictionary. They must conform to NSCoding (look that up on your own time) This would crash our app because Car is a custom object that doesn’t conform to NSCoding:
  5. Protocols and delegates A class that conforms to a protocol,

    will implement that protocols methods. The conforming class is the delegate. Think of it like a contract that the delegate signs forcing it to call methods based on an event. For example, people execute a certain protocol when a fire alarm sounds. The delegate pattern may be the single most important pattern for new Apple developers to master.
  6. UIViewController and UITableView - the most common delegate pairing Seen

    in the majority of iOS apps. Required delegate methods include: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section Your app may crash and your tableview will be useless if you fail to implement these methods.
  7. UIViewController and UITableView - the most common delegate pairing The

    interplay between these two objects is so important that 3 or our 4 view controllers will feature this pair.