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

MapSwift - lesson 12

leveton
June 11, 2017
42

MapSwift - lesson 12

leveton

June 11, 2017
Tweet

Transcript

  1. Swift sorting to filter collections Our settings controller allows us

    to pare locations down to a selected range. For this, we’ll use NSPredicates and sort descriptors - one of the more powerful Foundation API’s. But first we need to make a new model - an MSRange model - that will allow us to easily move ranges around the app.
  2. NSCopying Toggling our ranges back and forth, we need a

    reference to our original locations datasource. Being reference types, you can’t just assign copiedDataSource = dataSource. Anything that happens to copiedDataSource will affect dataSource because they share the same pointer. In order to copy objects entirely, with a new chunk of memory and a new pointer, we must use NSCopying. The object being copied must conform to the NSCopying protocol. Under the hood, copyWIthZone: is called on the object being copied.
  3. NSCopying You can make custom objects copyable by having them

    conform to NSCopying. Let’s see that with MSLocation: Now it can both act as an annotation on our map and be copied on the fly.
  4. The power of UITableView We’ve seen how much Apple bakes

    into UITableView with reusable cells, animated index paths, and delegates for many standard actions. Let’s use the moveRowAtIndexPath: and canMoveRowAtIndexPath: delegate methods to allow the user to reorder the set of location types. A little-used but powerful feature.
  5. The power of UITableView moveRowAt IndexPath and canMoveRowAt IndexPath are

    just delegate methods like cellForRowAt IndexPath or didSelectRowAt IndexPath Our settings view controller acts as a delegate for the cells being reordered. Certain events (like the reordering of cells) trigger these methods to be called. The view controller implements them
  6. The power of UITableView All this comes built into UITableView

    and UITableViewCell. No importing of third-party libraries and no having to write hundreds of lines of code (writing this app in the C you wrote in CS50).
  7. The MSLocation object is everywhere! Let’s review the advantages of

    objects: 1) We keep a mental model of the object across maps and tables. 2) We’re passing a 64 bit pointer around instead of a potentially huge chunk of memory. 3) The object is easily extendable.. What are other things we can do with our objects?
  8. Instruments Just like Xcode is a huge leap from the

    CS50 IDE, Instruments is like a super Valgrind There are the standard tools for profiling memory leaks and threading bugs but also tools for: • graphics usage • speed tests for Core Data fetches • a busy network layer • zombie objects • UI automated interactions (finger tapping, swiping, long-press) Much more..