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

MapSwift - lesson 8

leveton
June 01, 2017
27

MapSwift - lesson 8

leveton

June 01, 2017
Tweet

Transcript

  1. animations Like gesture recognizers and blocks, this is just the

    tip of the iceberg. Go more in depth by researching the options parameter animate(withDuration:delay:animations:). Look at common pitfalls regarding animations, e.g. your app’s process being interrupted causing the animation to fail.
  2. The singleton pattern Globals are evil, right? The changing of

    a global variable can have disastrous effects. Sometimes the alternative to have every class keep a property. Also there are times when you want a variable to change without the class that uses it to have to do any work.
  3. The singleton pattern Looking back at our detail view, we

    access the singleton’s themeColor property and set the view’s background color as such. Any singleton that’s an object should be checked for existence before use.
  4. The singleton pattern We can still change the property to

    var and reassign it. Then any object in the app that is using the theme color will now be working with a red theme color.
  5. The singleton pattern We could set the theme color in

    the appDelegate in didFinishLaunchingWithOptions so that’s it’s set before any of the app’s views are laid out.
  6. Sorting collections Let’s present our table logically by either sorting

    by title or distance. Swift has powerful sorting capabilities. But first let’s distinguish between sort() and sorted() with a playground. present tense verbs like ‘sort()’ are mutating functions - they permanently change the collection. Past tense verbs like ‘sorted()’ will make copies. Here we sort alphabetically from lowest to highest from the top of the table (the 0th index).
  7. Sorting collections Change the key and the ascending parameter to

    get the table sorted by distance from highest to lowest. Notice that ‘title’ and ‘distance’ are completely different types. Under the hood, sort() determines the type and goes from there.
  8. extensions Allows you to add functions to existing classes, structs,

    or enums. Extensions cannot contain stored properties but can contain computed properties.
  9. Favoriting a location In the detail view controller, we use

    UserDefaults to store a locationID inside an array when the user taps the favorite button.
  10. Favoriting a location In the detail view controller, we use

    UserDefaults to store a locationID inside an array when the user taps the favorite button.
  11. The cascading pattern UserDefaults gives us a quick-and-dirty way to

    store id’s, but how to inform our favorites view that a new location is favorited? The are several ways but we’ll use the cascading pattern which leverages our custom tab bar to propagate the change.
  12. UINavigationController We’ve seen two of the big three ways to

    handle navigation in iOS: 1) UITabbarController which handles the overall structure of our app. 2) Modal presentation which handled the details of our locations UINavigationController which we’ll see next, is the third common way to handle navigation iOS.