Lec 5 Obj-C part 2 CS 3800 Introduction to IOS programming Lecture 5 Summer 2011
Lec 5 Obj-C part 2 Announcements Read ch5 for Wednesday.
Lec 5 Obj-C part 2 Topics Quiz 3 Review Getters/Setters Property/synthesize Dot Notation Memory Management –Retain, release, dealloc, autorelease NS data types –NSString, NSArray
CS 3800 Su 11 Beg. IOS Dev Objective-C alloc init ivars and functions Multiple parameters Property, Synthesize L4 Obj C part 1 Memory management Protocols Categories Inheritance
CS 3800 Su 11 Beg. IOS Dev Objective-C Classes NSObject NSArray NSString NSSet NSDictionary NSDate Mutable & Immutable L4 Obj C part 1
Lec 5 Obj-C part 2 NSString (immutable) child of NSObject.. means? creating –[ [ NSString alloc] init….] (many variations) Example: –convenience functions – [NSString conFuncName] –(many variations) Example:
Lec 5 Obj-C part 2 NSString - function survey length isEqualToString charAtIndex hash Conversion: –integerValue –doubleValue many more IMMUTABLE!?
Lec 5 Obj-C part 2 The point of the next 8 slides Understand the impact of the property attribute choices Use setters/getters inside the class –They should do 90% of memory management for you Build and Analyze tool
Lec 5 Obj-C part 2 Property, synthesize redux Employee Class contains objects! Open starter project.
Lec 5 Obj-C part 2 Property, synthesize redux Property options; assign simple assignment (default) retain retain the new version, release old copy creates a copy
Lec 5 Obj-C part 2 Build and analyze
Lec 5 Obj-C part 2 Under the hood of the setter #1 Assign: attribute self.name = aNewName; -(void) setName:(NSString*)aNewName { name = aNewName; } Don’t: self.name = ….
Lec 5 Obj-C part 2 Under the hood of the setter #2 retain: self.name = aNewName; -(void) setName:(NSString*)aNewName { if ( name == aNewName ) { [name release]; [ aNewName retain]; name = aNewName; }
Lec 5 Obj-C part 2 Property, synthesize redux Property options; readwrite (default) readonly (no setter is created)
Lec 5 Obj-C part 2 Property, synthesize redux Property options; nonatomic atomic ( default, but does not exist)
Lec 5 Obj-C part 2 Property, synthesize redux getter= Custom getters/setters
Lec 5 Obj-C part 2 Property, synthesize redux Do: Use setters/getters within a class Instead of direct iVars Example: initializer
Lec 5 Obj-C part 2 NSArray Order collection Immutable (after creation) + (id)arrayWithObjects:(id) firstObject, …., nil; -(int) count; -(id) objectAtIndex:(int) index; -(NSArray*) sortedArrayUsingSelector:(SEL)aSelector; -Application: Creating a UIPickerView