Εμφάνιση αναρτήσεων με ετικέτα ios. Εμφάνιση όλων των αναρτήσεων
Εμφάνιση αναρτήσεων με ετικέτα ios. Εμφάνιση όλων των αναρτήσεων

Τρίτη 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.  

Δευτέρα 23 Απριλίου 2012

Chapter 2 - notes


  • a method is a chunk of code that can be executed 
  • a message is the act of asking a class or object to execute a method. 
  • reveal the log navigator using Command-7
  • At NSLog the first argument is required and must be an NSString instance. This instance is called the format string and it contains text and a number of tokens. When %@ is encountered in the format string , that argument is sent the message description
  • In objective-C an array does not actually contain the objects that belong to it; instead it holds a pointer to each object. (references). This means primitives and C structures cannot be added to an array. 
  • A single array can contain objects of different types. 
  • If you need to add "holes" to an array, you must use NSNull
  • Stylish Cocoa Touch programmers always follow the naming conventions (and they are a lot of them).
  • importing a file is the same as including a file in the C, except you are ensured that the file will only be included once. 
  • the designated initializer makes sure that every instance variable of an object is valid. 
  • in the designated initializer, the first thing you always do is call the superclass's designated initializer using super. The last thing you do is return a pointer to the successfully initialized object using self.
  • using initializers as a chain, reduces the chance for error and makes maintaining the code easier.  
  • init methods are always declared to return id.
  • We call it the isa pointer because an object "is a" instance of that class.
  • An instance method uses the - character just before the return type
  • a class method uses the + character
  • Class methods come first, followed by initializers. This is a convention that makes your header files easier to read. 
  • NSInteger is not an object but a type definition for "unsigned long"
  • Class methods should use self in convenience methods  instead of their class name so that a subclass can be sent the same message. 
  • Exceptions are also known as run-time errors.
  • unrecognized selector means the message you are sending isn't implemented by the receiver.  
  • If two classes have the same name is known as a namespace collision
  • Objective-C has no notion of namespaces. Instead, we prefix class names with two or three lettres to keep them distinct. For example, instead of call name Item we use the MMRItem, where MMR is the first letters of my mythical company. 
#source: Big Nerd Ranch Guide  - iOS Programming 3rd edition.