A tap gesture will show and hide the distance label while a pan gesture will allow us to move the dismiss button around the detail view. Recognizers are easy to set up and offer a powerful API for developers to utilize
code to set up the gesture recognizers and assign them to views. Some Caveats: 1) A gesture recognizer can be added to any subclass of UIView 2) Two views cannot share a gesture recognizer. Last one in! 3) Often you have to set a view’s userInteractionEnabled property to true. 4) Do not overuse gesture recognizers - see Apple’s Human Interface Guidelines. 5) Notice that the dismiss button still fires even after you pan it around the view, this fact has allowed many a developer to create simple 2D games.
curly braces means it’s a block type variable but what is that exactly... A block variable encapsulates code that is executed at either a different time, on a different thread, or both. In our case, the code in the block isn’t executed until the view controller leaves the Window.
log out “reached end of didTapDimiss scope” before “completion block fired”. This is counter to what normally happens where code is executed sequentially from top to bottom.
to execute the block variable until some event has occurred. In our case, the event is the view controller sliding off of the main window. A block doesn’t have to be inline. We can declare it as a separate variable:
code is a custom animation. A class method on UIView that takes two blocks handling both the animation and the code to execute when the animation finishes.
have done a ton of work to create an API that is simple for us to implement. Just toss your desired animation inside the curly braces of the animation block and let UIKit do the rest:
of the iceberg. Go more in depth by researching the options parameter animateWithDuration. Look at pitfalls of animations e.g. your app’s process being interrupted causing the animation to fail.
a global variable can have disastrous effects. So mostly yes, but 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.
initialize the singleton. the @synchronized compiler directive will prevent other objects from accessing this class while the initialization is taking place.
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.
by title or distance. NSSortDescriptor is magic - it can sort by primitives (CGFloat distance) and certain objects (NSString *title). Here we sort alphabetically from lowest to highest from the top of the table (the 0th index)
get the table sorted by distance from highest to lowest. Notice that ‘title’ and ‘distance’ are completely different types. Under the hood, sortDescriptorWithKey determines the type and goes from there.