Ios: Writing Apps Like A Boss: Tommy Macwilliam
Ios: Writing Apps Like A Boss: Tommy Macwilliam
Tommy MacWilliam
Today
Objective-C XCode Single-Page Apps Navigation
Objective-C
like C, but with more features! no more malloc larger standard library
Object-Oriented Programming
structs that can have functions as members inheritance from other classes data encapsulation: good design!
Object-Oriented Programming
declare classes with @interface dene classes with @implementation declare members with @property
Message Passing
-(void)init; -(void)initWithInt:(int)i;
-(void)initWithInt:(int)i andFloat:(float)f;
Message Passing
Strings
NSString* s = @cs50 [s length] [s characterAtIndex:0]
Arrays
NSMutableArray* a = [[NSMutableArray alloc] init]; [a addObject:@cs50]; [a removeObjectAtIndex:0];
Objective-C Example
View Controllers
class representing one screen properties for views (aka controls) methods for actions
Building Interfaces
drag and drop views from object library IBOutlet: wire up views to properties IBAction: wire up events to methods
Wiring IBOutlets
Ctrl-Click View Controller Drag to view Select property to wire to
Wiring IBActions
Ctrl-Click view Drag to View Controller Select action to wire to
Hello, iOS
Like a boss.
Tags
what if we dont want a property for
every view?
[self.view viewWithTag:0]
Like a boss.
Protocols
@protocol SomeProtocol -(void)foo; -(int)bar:(int)baz; @end @interface ViewController : UIViewController <SomeProtocol>
Delegates
designate a class to handle actions class implements a protocol promising it
can handle actions
TextFieldDelegate
Table Views
how many sections are in the table? how many rows are in this section? what does this cell look like?
tableView:cellForRowAtIndexPath:
tableView:numberOfSectionsInTableView:
tableView:numberOfRowsInSection:
dequeueReusableCellWithIdentifier:
Cell Properties
textLabel accessoryType
...
Storyboarding
Drag view controller from object library Object Inspector > Custom Class Choose class name from drop-down
Segues
connections between view controllers Ctrl-click view that will trigger action Drag to view controller to transition to
prepareForSegue
segues have unique identiers cast destinationViewController set properties of new view controller
Property Lists
easy data storage key/value pairs with arrays, dictionaries,
etc. as values
MLB Mobile
Like a boss.
Documentation
https://developer.apple.com/library/ios/
navigation/
Questions?