Download presentation
Presentation is loading. Please wait.
Published byGriselda Simon Modified over 8 years ago
1
Lec 5 Obj-C part 2 CS 3800 Introduction to IOS programming Lecture 5 Summer 2011
2
Lec 5 Obj-C part 2 Announcements Read ch5 for Wednesday.
3
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
4
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
5
CS 3800 Su 11 Beg. IOS Dev Objective-C Classes NSObject NSArray NSString NSSet NSDictionary NSDate Mutable & Immutable L4 Obj C part 1
6
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:
7
Lec 5 Obj-C part 2 NSString - function survey length isEqualToString charAtIndex hash Conversion: –integerValue –doubleValue many more IMMUTABLE!?
8
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
9
Lec 5 Obj-C part 2 Property, synthesize redux Employee Class contains objects! Open starter project.
10
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
11
Lec 5 Obj-C part 2 Build and analyze
12
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 = ….
13
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; }
14
Lec 5 Obj-C part 2 Property, synthesize redux Property options; readwrite (default) readonly (no setter is created)
15
Lec 5 Obj-C part 2 Property, synthesize redux Property options; nonatomic atomic ( default, but does not exist)
16
Lec 5 Obj-C part 2 Property, synthesize redux getter= Custom getters/setters
17
Lec 5 Obj-C part 2 Property, synthesize redux Do: Use setters/getters within a class Instead of direct iVars Example: initializer
18
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.