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

MapSwift - lesson 5

leveton
May 17, 2017
26

MapSwift - lesson 5

leveton

May 17, 2017
Tweet

Transcript

  1. UIViewController and UITableView - the most common delegate pairing Seen

    in the majority of iOS apps. Required delegate methods include: func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int Your app may crash and your tableview will be useless if you fail to implement these methods.
  2. UIViewController and UITableView - the most common delegate pairing Three

    out of four of our view controller’s feature this pair. We need the practice.
  3. Understanding NSIndexPath NSIndexPath has a row and a section property.

    Think of sections as columns. Our locations table has only one column, but our settings table will have three.
  4. Understanding NSIndexPath Switch to the lesson 8 branch and run

    the app to see this more clearly. Our locations table only has one section so indexPath.section will be 0, we care about is indexPath.row
  5. Using objects to model our locations What properties should the

    location object have? 1) title 2) a 2D coordinate 3) preferably a photo 4) a distance from our location
  6. Using objects to model our locations Where are we going

    to use the object? 1) Our map 2) To populate data for our table view cells 3) In our detail view when a user taps on a table view cell 4) In our favorites view controller for favoriting locations 5) In our global singleton (sparingly)
  7. Using objects to model our locations Why not just use

    a dictionary?? Objects can have methods that you can use to calculate things or do things specific to that object.
  8. The View Controller Lifecycle 1) init(). Be careful what code

    you put here. The view hasn’t been laid out yet. 2) yourView.someProperty = someValue. In the setter, subviews are often initialized. 3) viewDidLoad. The view is loaded into memory via presentViewController or pushViewController or setViewControllers. 4) viewWillAppear. For code you want executed every time the controller is atop the window hierarchy. 5) viewWillLayoutSubviews. Typically set frames here as this gets called when the device orientation changes amongst other events (e.g. when a table is reloaded). 6) viewDidAppear. Put animation code here to ensure that the animation block fires and to ensure that the user doesn’t see the view after the animation has begun.
  9. Parsing JSON Before we get into networking, we use a

    dummy JSON file for our datasource. Data, Bundle, and JSONSerialization are all subclasses of NSObject. Get familiar with the class methods shown here. They’re used often for converting data from the filesystem or some other source into Swift code.