Big Nerd Ranch iOS Training Day 6 & 7
On Day 6 & 7, we covered a wide variety of topics. Things of note are...
Web Services - how to call it and parse things from it
NSXMLParser
NSJSONSerialization
Touch Events and how they all inherit from UIResponder
Instruments in XCode and how it can help with leaks, what lines of code is taking a long time to process and etc.
Core Animation aka LayerKit
Core Data, this is an internal storage mechanism that you can bind to controls within iOS controls
Key Value Observing (KVO) and Key Value Coding (KVC)
Here are my notes for these 2 days.
Day 6
developer.apple.com
Sample code
Order in things arrive when starting an application
+ initialize
Don’t init super
Note: This is a class method
- init
- application: didFinishLaunchingWithOptions:
NSStringFromSelector(_cmd)
Shows the method that is currently running
You have to put this on each method you want to log
[[NSNotificationCenter defaultCenter] addObserverForName:nil object:nil queue:nil usingBlock:^(NSNotification *n) { NSLog(@”notified! %@”, [n name]); }]
A way to look at all registered notifications on the application
Doesn’t matter where this is called, it will list out the notifications on NSLog
- (BOOL)respondsToSelector:(SEL)aSelector { NSLog(@”Awww, someone cares! about: %@”, NSStringFromSelect(aSelector)); return [super respondsToSelector: aSelector]; }
Put this method in the app delegate, this will show all possible delegate methods that will be asked
Not sure if you need to put this in other classes, you might need to
Web Services
No DB internally in iPhone
UIWebView
You can inject JavaScript to the page!
NSXMLParser
XML Parser
libXML in C
Use this on the lower level if performance becomes an issue
According to Scott, this will eat NSXMLParser for lunch...
NSJSONSerialization
JSON Parser
Question: Why is it that in Homepwner, some properties declared in the top viewcontroller are strong and others are weak?
If you notice, weak is referenced in IBOutlet. Reason why this is the case, these outlets belong in the “Content View” (open up the .xib file in Interface Builder) and the retain count is maintained by the view controller that contains it.
Note: If ARC is turned on, it will take care of this automatically and you don’t have to worry about it.
StoryBoard
Scott: Great for prototyping and might not want to use for coding
Will be a challenge to integrate storyboard with .xib approach
Not so good working with a team
Does not scale well into a larger application
Touch Events and UIResponder
Override these…
- touchesBegan: withEvent
- touchesMoved: withEvent
- touchesEnded: withEvent
- touchesCancelled: withEvent
UIGestureRecognizer
add them to views
Note: There is a really interesting method that was written that checks the closest line to a point that is tapped on screen in Chapter 21 - Page 430.
Note: Stopped at Page: 434
Debugger
You can right click on the breakpoint and do more stuff to the spot on the breakpoint
lldb - command line for debugging
Instruments
Manage Schemes - specify what you would like to do when running the profiling tools
For more information, look at chapter 22
“Instruments User Guide” in Apple Developer if you want more information
Core Animation aka LayerKit (Chapter 23)
Instead of redrawing, it uses layers to make sure the animations are smooth
For everything view in the hierarchy, there is a backing view in the layer
It actually creates an illusion, it creates an animation presentation, but the view actually moves there directly
This is awesome, because we can animate all kinds of stuff because every view have a layer
CALayer and CAAnimation
See samples: MoveMe, Touches
Day 7
TempChat sample code
Talk about sockets
NSUserDefaults
- registerDefaults
Takes an NSDictionary with the factory defaults. These will be used if no other values have been set
Can add Settings Bundle that loads the preferences of NSUserDefaults so that your user can go to the Settings menu and change these preferences
Singleton
A method that starts with “shared” it generally means its a Singleton
Scott Ritchie:
Core Data
Not an interface to a SQL database!!! It is its own internal mini-relational database, SQLite.
Reason why you would use this is because just saving persistence as an archive file into the filesystem is its all or nothing nature: to access anything in the archive, you must unarchive the entire file. Core Data has better performance because it can fetch a small subset of the stored objects.
Persistence Framework - This is just an internal way to store objects locally
You can bind Core Data to controls in iOS, just that you can’t do it in Interface Builder for iOS, but… you can do it in Cocoa
Fetches objects from store (file)
Tracks changes made to objects
Saves changes to store (file)
Store types:
SQLite (file)
XML (file) Not on iPhone
Binary (file)
In memory
NSManagedObjectContext
Key Value Observing (KVO) and Key Value Coding (KVC)
In the view controller that “monitors” things specified (via a key path), this way, for instance, if something is changed in the HypnoTime app, you redraw something ([self setNeedsDisplay];)













