Share
Embed
Transcript
16 slides
-
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. -
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. -
The singleton pattern Singetons are much simpler in Swift than
Objective-C BEFORE: -
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. -
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. -
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. -
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). -
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. -
extensions Allows you to add functions to existing classes, structs,
or enums. Extensions cannot contain stored properties but can contain computed properties. -
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. -
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. -
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. -
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.