Τρίτη, 1 Μαΐου 2012

Chapter 4 - Core Location Framework



  • a project always has at least one target. When you build and run, you build and run the target, not the project. 
  • a framework is a collection of related classes that you can add to a target
  • To add a framework to your target, select Targets - Build Phases tab - click the plus (+) button in the bottom left corner of the Link Binary With Libraries section. 
  • CCLocationManager is the class that interfaces with the location hardware of the device. 
  • There is a tradeoff between the accuracy of the location and the amount of time and battery life required to determine the location. 
  • Every CCLocationManager has a delegate property, and we can set this property to point to the object that we want to receive the "location found" message. 
  • When you set the delegate property of the CLLocationManager and implemented the two location finding methods in WhereamiViewController, you were using a design pattern called delegation
  • Delegation is an object-oriented approach to callbacks.
  • Delegate properties are __unsafe_unretained. Because delegate is unsafe unretained instead of weak, it is not automatically set to nil when the object it points to is destroyed. You have to do that yourself in the delegate object's dealloc method. 
  • In delegation, an object can only send its delegate messages from a specific set listed in a protocol. 
  • There is no build-in way for two (or more) callback functions to coordinate and share information. 
  • In delegation, an object can only send its delegate messages from a specific set listed in a protocol. 
  • Protocol is declared with the directive @protocol
  • A protocol is not a class; it is simply a list of methods. Instead, implementation is left to each class that conforms to the protocol. 
  • We call protocols used for delegation delegate protocols, and the naming convention for a delegate protocol is the name of the delegating class plus the word Delegate. 
  • Methods declared in a protocol can be required or optional. 
  • Before sending an optional message, the object first asks its delegate if it is okay to send that message by sending another message, respondsToSelector: if ([[self delegate] respondsToSelector:updateMethod])
  • if a method in a protocol is required, then the message will be sent without checking first. 
  • The debug navigator shows a stack trace that shows you the methods and functions whose frames were in the stack when the application broke. Notice that the methodes that you implemented are in black text and the methods belonging to Apple are in gray. 
  • The first item under self is its superclass.
  • Automatically set a breakpoint on any line that causes your application to crash or that causes an exception to be thrown. To get the debugger to do this, we need to add a breakpoint for all exceptions. Select the debug navigator. Then at the bottome of the navigator area, click the + icon and select Add Exception Breakpoint. 
  •  Here is what each build phase does:  
  1. Compile Sources:Preprocessing (creates an intermediate file for each .m,  see # directive), Compiling (takes the Objective-C code from an intermediate file and turns it into machine code and stores it in an object file .o).
  2. Link Binary With Libraries - this allow your code to use classes from frameworks (A framework however, has pre-compiled its implementation files - that's why in Objective C you can't see the implementation files in a framework.
  3. Copy Bundle Resources: theses resources are the data files that your application uses at runtime, like XIB files, images sounds etc. 
  • when you see linker errors, it is typically because you did not add the appropriate framework.