6. Where we’re going:
• Quick Objective-c and iOS review
• Overview of iOS 5 additions and changes
7. Where we’re going:
• Quick Objective-c and iOS review
• Overview of iOS 5 additions and changes
• Introducing Lobstagram
8. Where we’re going:
• Quick Objective-c and iOS review
• Overview of iOS 5 additions and changes
• Introducing Lobstagram
• Other iOS 5 features (as time permits)
27. Getting Started
• Recommended but not required
• Some knowledge of C
• malloc() . . . free() ?
• Some knowledge of design patterns:
28. Getting Started
• Recommended but not required
• Some knowledge of C
• malloc() . . . free() ?
• Some knowledge of design patterns:
• MVC, Singleton, Delegation
35. Obj-C in 10 minutes
• All the things you know from C
36. Obj-C in 10 minutes
• All the things you know from C
• Variables are typed:
37. Obj-C in 10 minutes
• All the things you know from C
• Variables are typed:
• int, float, double, char
38. Obj-C in 10 minutes
• All the things you know from C
• Variables are typed:
• int, float, double, char
int foo = 5;
39. Obj-C in 10 minutes
• All the things you know from C
• Variables are typed:
• int, float, double, char
int foo = 5;
• Separate compilation
40. Obj-C in 10 minutes
• All the things you know from C
• Variables are typed:
• int, float, double, char
int foo = 5;
• Separate compilation
• .h for interface declaration
41. Obj-C in 10 minutes
• All the things you know from C
• Variables are typed:
• int, float, double, char
int foo = 5;
• Separate compilation
• .h for interface declaration
• .m for implementation (instead of .c)
43. Obj-C in 10 minutes
• Functions / Methods have return types and
typed arguments
44. Obj-C in 10 minutes
• Functions / Methods have return types and
typed arguments
int sumOfItems(int i, int j)
{
return i + j;
}
45. Obj-C in 10 minutes
• Functions / Methods have return types and
typed arguments
int sumOfItems(int i, int j)
{
return i + j;
}
• Other types
46. Obj-C in 10 minutes
• Functions / Methods have return types and
typed arguments
int sumOfItems(int i, int j)
{
return i + j;
}
• Other types
• void, NULL
47. Obj-C in 10 minutes
• Functions / Methods have return types and
typed arguments
int sumOfItems(int i, int j)
{
return i + j;
}
• Other types
• void, NULL
• pointers to types (int *, void *)
50. Obj-C in 10 minutes
• Objective-C Additions:
• BOOL - YES / NO
51. Obj-C in 10 minutes
• Objective-C Additions:
• BOOL - YES / NO
BOOL isSet = YES;
52. Obj-C in 10 minutes
• Objective-C Additions:
• BOOL - YES / NO
BOOL isSet = YES;
• id - strictly a pointer to an object
53. Obj-C in 10 minutes
• Objective-C Additions:
• BOOL - YES / NO
BOOL isSet = YES;
• id - strictly a pointer to an object
• nil - a zero’d out pointer
54. Obj-C in 10 minutes
• Objective-C Additions:
• BOOL - YES / NO
BOOL isSet = YES;
• id - strictly a pointer to an object
• nil - a zero’d out pointer
• nil != (necessarily) NULL or 0
57. Obj-C in 10 minutes
• Classes
• Exist as a class pair
58. Obj-C in 10 minutes
• Classes
• Exist as a class pair
• Instance variables and instance methods act
on an instance object
59. Obj-C in 10 minutes
• Classes
• Exist as a class pair
• Instance variables and instance methods act
on an instance object
• Class (static) methods act on the class
object
60. Obj-C in 10 minutes
• Classes
• Exist as a class pair
• Instance variables and instance methods act
on an instance object
• Class (static) methods act on the class
object
• There is only ever one class object at any
given time
61. Obj-C in 10 minutes
• Classes
• Exist as a class pair
• Instance variables and instance methods act
on an instance object
• Class (static) methods act on the class
object
• There is only ever one class object at any
given time
• Class variables really don’t exist
62. Obj-C in 10 minutes
• Classes
#import <Foundation/Foundation.h>
@interface MyClass : NSObject
{
id aChildObject;
NSArray *someItems;
}
+ (NSString *)className;
- (void)logMe;
@property (nonatomic, retain) id aChildObject;
@end
63. Obj-C in 10 minutes
• Classes Include a header
#import <Foundation/Foundation.h>
file
@interface MyClass : NSObject
{
id aChildObject;
NSArray *someItems;
}
+ (NSString *)className;
- (void)logMe;
@property (nonatomic, retain) id aChildObject;
@end
87. Obj-C in 10 minutes
• What’s with all the ‘@’ and ‘[ ]’?
88. Obj-C in 10 minutes
• What’s with all the ‘@’ and ‘[ ]’?
•@
• Objective-C keywords
• Initializer for string constants
89. Obj-C in 10 minutes
• What’s with all the ‘@’ and ‘[ ]’?
•@
• Objective-C keywords
• Initializer for string constants
• ‘[]’
• “Send a message to an object”
• Like calling a method, but more dynamic
110. Key Objects
• UIViewController
• Contains a view, manages all the information and
widgets on the view.
• One Controller per view (screen)
111. Key Objects
• UIViewController
• Contains a view, manages all the information and
widgets on the view.
• One Controller per view (screen)
• UIView
• The view itself. All UI widgets inherit from
UIView.
• Objects on a view are “subviews” of that view
119. Key Patterns
• Delegation (Datasource)
• Alleviates subclassing
“I’m a table view. The user tapped the fourth cell.
Thought you should know.”
120. Key Patterns
• Delegation (Datasource)
• Alleviates subclassing
“I’m a table view. You need to give me a cell object to
display at row 5. I don’t really care what’s in it.”
135. iOS 5
• Thousands of new APIs
• Newly available frameworks
• Game Center
• Automatic Reference Counting
• Storyboards
• iCloud
• It’s really really really big
144. A Brief Tour
• A Table View of images already
taken
• Camera button chooses a photo
(or takes a photo)
145. A Brief Tour
• A Table View of images already
taken
• Camera button chooses a photo
(or takes a photo)
• Next view applies the photo title
and saves to CoreData
146. A Brief Tour
• A Table View of images already
taken
• Camera button chooses a photo
(or takes a photo)
• Next view applies the photo title
and saves to CoreData
• Table refreshes.
147. A Brief Tour
• A Table View of images already
taken
• Camera button chooses a photo
(or takes a photo)
• Next view applies the photo title
and saves to CoreData
• Table refreshes.
• Not worth $1 Billion
150. A Brief Tour
• UITableView as described earlier.
• UIImagePickerViewController is an
easy to use built in control.
151. A Brief Tour
• UITableView as described earlier.
• UIImagePickerViewController is an
easy to use built in control.
• CoreData is an ORM on steroids
for working with persistent
storage.
152. A Brief Tour
• UITableView as described earlier.
• UIImagePickerViewController is an
easy to use built in control.
• CoreData is an ORM on steroids
for working with persistent
storage.
• All written in ARC code.
155. The Dark Ages
• Manual Memory Management
• No garbage collection as in C#, Java, Ruby,
PHP, Python
156. The Dark Ages
• Manual Memory Management
• No garbage collection as in C#, Java, Ruby,
PHP, Python
• Reference counting system implemented on
NSObject.
157. The Dark Ages
• Manual Memory Management
• No garbage collection as in C#, Java, Ruby,
PHP, Python
• Reference counting system implemented on
NSObject.
• alloc . . . init
158. The Dark Ages
• Manual Memory Management
• No garbage collection as in C#, Java, Ruby,
PHP, Python
• Reference counting system implemented on
NSObject.
• alloc . . . init
• retain
159. The Dark Ages
• Manual Memory Management
• No garbage collection as in C#, Java, Ruby,
PHP, Python
• Reference counting system implemented on
NSObject.
• alloc . . . init
• retain
• release
160. The Dark Ages
• Manual Memory Management
• No garbage collection as in C#, Java, Ruby,
PHP, Python
• Reference counting system implemented on
NSObject.
• alloc . . . init
• retain
• release
• autorelease
161. The Dark Ages
• Manual Memory Management
• No garbage collection as in C#, Java, Ruby,
PHP, Python
• Reference counting system implemented on
NSObject.
• alloc . . . init
• retain
• release
• autorelease
• dealloc
170. ARC Decorators
• __strong - owning reference (default)
• __weak - non-owning reference
• __unsafe_unretained - manual management
• __autoreleasing - used in out parameters
171. ARC Decorators
• __strong - owning reference (default)
• __weak - non-owning reference
• __unsafe_unretained - manual management
• __autoreleasing - used in out parameters
• No dealloc
172. Using __weak
• Use __weak to refer to an object that
you’re confident will be retained elsewhere.
173. Using __weak
• Use __weak to refer to an object that
you’re confident will be retained elsewhere.
NSArray *array = [NSArray arrayWithObjects:@"foo", @"bar",
@"baz", nil];
// The array is owning all the objects in it, so we don't
// need a strong reference here (but there's nothing wrong
with it)
NSString * __weak first = [array objectAtIndex:0];
177. __unsafe_unretained
• Used for backwards compatibility with iOS
4.
• Pointer is NOT nil’d out after deallocation.
// nil initialization is automatic
NSNumber * __unsafe_unretained n = nil;
if (YES)
{
n = [[NSNumber alloc] initWithInt:25];
NSLog(@"%@", n);
}
// n loses scope
NSLog(@"%@", n); // CRASH! (probably)
178. __unsafe_unretained
• Used for backwards compatibility with iOS
4.
• Pointer is NOT nil’d out after deallocation.
// nil initialization is automatic
NSNumber * __unsafe_unretained n = nil;
if (YES)
{
n = [[NSNumber alloc] initWithInt:25];
NSLog(@"%@", n);
}
// n loses scope
n = nil;
NSLog(@"%@", n); // a-ok
179. __autoreleasing
• Used with out parameters
NSError * __autoreleasing error = nil;
if (![managedObjectContext save:&error])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"The photo could not be saved"
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alert show];
}
else
{
[delegate photoSettingsViewController:self didSaveNewPhoto:photo];
}
• (Note, the compiler will rewrite this if you
use a strong reference)
181. So what?
• ARC drastically reduces up front development
time.
182. So what?
• ARC drastically reduces up front development
time.
• ARC drastically reduces debugging time.
183. So what?
• ARC drastically reduces up front development
time.
• ARC drastically reduces debugging time.
• ARC is not perfect:
184. So what?
• ARC drastically reduces up front development
time.
• ARC drastically reduces debugging time.
• ARC is not perfect:
• Still possible to have retain cycle
185. So what?
• ARC drastically reduces up front development
time.
• ARC drastically reduces debugging time.
• ARC is not perfect:
• Still possible to have retain cycle
• Still need to understand pointer scope
186. So what?
• ARC drastically reduces up front development
time.
• ARC drastically reduces debugging time.
• ARC is not perfect:
• Still possible to have retain cycle
• Still need to understand pointer scope
• Doesn’t work on CF objects
187. So what?
• ARC drastically reduces up front development
time.
• ARC drastically reduces debugging time.
• ARC is not perfect:
• Still possible to have retain cycle
• Still need to understand pointer scope
• Doesn’t work on CF objects
• The compiler is smarter than you.
194. Twitter.framework
• TWTweetComposeViewController
• Super easy view for composing a tweet
• TWRequest
• Encapsulates the handling of HTTP
requests to the Twitter server.
• Requires the user to have set up Twitter in
the device’s settings.
195. Tweet Composer
• Appears looking great
automatically.
• Can add links and images
• Literally zero
configuration.
201. The Dark Ages
• UI Customization was labor intensive
• Every instance of a widget had to be
customized individually.
202. The Dark Ages
• UI Customization was labor intensive
• Every instance of a widget had to be
customized individually.
• Subclassing
203. The Dark Ages
• UI Customization was labor intensive
• Every instance of a widget had to be
customized individually.
• Subclassing
• Helper methods
204. The Dark Ages
• UI Customization was labor intensive
• Every instance of a widget had to be
customized individually.
• Subclassing
• Helper methods
• Overriding drawRect or haphazardly
adding subviews.
205. UIAppearance
• Certain UI Widgets expose an “appearance
proxy” which can be customized once and
the look persists everywhere.
[[UINavigationBar appearance] setTitleTextAttributes:navBarTextProperties];
[[UILabel appearanceWhenContainedIn:[UIButton class], nil] setTextColor:
[UIColor whiteColor]];
• Elements can also be customized
individually via the same methods.
206. What it’s not . . .
• A Cascading Style Sheet
• Outermost rule breaks a tie-
breaker
• No way to specify things by Id
• Unexpected consequences . . .
223. CoreImage Workflow
• Create a CIContext
• Grab an input image
• Declare and configure a filter
• Get the output image from the filter
224. CoreImage Workflow
• Create a CIContext
• Grab an input image
• Declare and configure a filter
• Get the output image from the filter
• Billion dollar profit
225. Some caveats
• Documentation is scant
• The core image filter list applies to
MacOS only.
• To get the full list available on the iPhone:
NSLog(@"%@", [CIFilter filterNamesInCategory:kCICategoryBuiltIn]);
• There are filters in the device that aren’t
documented.