English | 2014 | ISBN: 978-0321942050 | 560 Pages | EPUB | 10 MB
Updated and expanded to cover iOS 7 and Xcode 5, iOS Programming: The Big Nerd Ranch Guide leads you through the essential concepts, tools, and techniques for developing iOS applications. After completing this book, you will have the know-how and the confidence you need to tackle iOS projects of your own. Based on Big Nerd Ranch’s popular iOS Bootcamp course and its well-tested materials and methodology, this bestselling guide teaches iOS concepts and coding in tandem. The result is instruction that is relevant and useful.
Throughout the book, the authors explain what’s important and share their insights into the larger context of the iOS platform. You get a real understanding of how iOS development works, the many features that are available, and when and where to apply what you’ve learned.
Here are some of the topics covered:
- Xcode 5, Instruments, and Storyboards
- Building interfaces using the iOS 7 aesthetic
- ARC and strong and weak references
- Handling touch events and gestures
- Toolbars, navigation controllers, and split view controllers
- Using Auto Layout to scale user interfaces
- Using Dynamic Type to scale fonts
- Localization and Internationalization
- Block syntax and use
- Saving/loading data: Archiving and Core Data
- Core Location and Map Kit
- Communicating with web services using JSON
- Using the Model-View-Controller-Store design pattern
An initializer takes arguments that the object can use to initialize itself. Often, a class has multiple initializers because instances can have different initialization needs. For instance, the first initializer that you declared takes three arguments that it uses to configure the item’s name, value, and serial number. So you need all of this information to initialize an instance with this method. What if you only know the item’s name? Then you can use the second initializer.
First, at the beginning of this method, notice the syntax for creating the two arrays randomAdjectiveList and randomNounList – an @ symbol followed by square brackets. Within the brackets is a comma-delimited list of objects that will populate the array. (In this case, the objects are instances of NSString.) This syntax is shorthand for creating instances of NSArray. Note that it always creates an immutable array. You can only use this shorthand if you do not need the resulting array to be mutable.
After creating the arrays, randomItem creates a string from a random adjective and noun, a random integer value, and another string from random numbers and letters.
Finally, the method creates an instance of BNRItem and sends it the designated initializer message with these randomly-created objects and int as parameters.
In this method, you also used stringWithFormat:, which is a class method of NSString. This message is sent directly to the NSString class, and the method returns an NSString instance with the passed-in parameters. In Objective-C, class methods that return an object of their type (like stringWithFormat: and randomItem) are called convenience methods.
Notice the use of self in randomItem. Because randomItem is a class method, self refers to the BNRItem class itself instead of an instance. Class methods should use self in convenience methods instead of their class name so that a subclass can be sent the same message. In this case, if you create a subclass of BNRItem called BNRToxicWasteItem, you could do this: