0% found this document useful (0 votes)
59 views

Ios: Writing Apps Like A Boss: Tommy Macwilliam

This document provides an overview of key concepts for writing iOS apps using Objective-C including: object-oriented programming with classes, properties, inheritance, and message passing; strings and arrays; view controllers and building interfaces with outlets and actions; creating new classes; table views with cells; storyboarding and segues; protocols and delegates; and property lists for data storage. The document emphasizes building apps "like a boss" and provides documentation resources for further learning.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views

Ios: Writing Apps Like A Boss: Tommy Macwilliam

This document provides an overview of key concepts for writing iOS apps using Objective-C including: object-oriented programming with classes, properties, inheritance, and message passing; strings and arrays; view controllers and building interfaces with outlets and actions; creating new classes; table views with cells; storyboarding and segues; protocols and delegates; and property lists for data storage. The document emphasizes building apps "like a boss" and provides documentation resources for further learning.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 36

iOS: Writing Apps like a Boss

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

NSObject* o = [[NSObject alloc] init];

[o foo]; [o bar:5]; [o baz:5 qux:1.0];

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

self: current instance of class

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

Creating new Classes


Ctrl-click project folder on left New File > Objective-C class

Hello, iOS

Like a boss.

Tags
what if we dont want a property for
every view?

tag: unique numerical identier

[self.view viewWithTag:0]

Tic Tac Toe

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

instantiate the class

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:

Table View Cells


cells are cached and reused for
performance

types of cells have unique string identiers

dequeueReusableCellWithIdentifier:

Cell Properties

textLabel accessoryType

...

Hello, Table Views

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

just like JSON, but XML under the hood

MLB Mobile

Like a boss.

Documentation
https://developer.apple.com/library/ios/
navigation/

http://bit.ly/ybWlmh http://bit.ly/zWrRPl http://cs164.net http://cs76.net

Questions?

You might also like