Lecture 04_0

Lecture 04_0 - CS193p Spring 2010 Wednesday, April 7, 2010...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
CS193p Spring 2010 Wednesday, April 7, 2010
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Announcements Get your Axess situation right. If you have not turned in homework, e-mail us. As they say in Air TrafFc Control: state your intentions. Homework Any questions about the homework? Wednesday, April 7, 2010
Background image of page 2
Communication E-mail Questions are best sent to cs193p@cs.stanford.edu Sending directly to instructor or TA’s risks slow response. Web Site Very Important! http://cs193p.stanford.edu All lectures, assignments, code, etc. will be there. This site will be your best friend when it comes to getting info. Wednesday, April 7, 2010
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
To day ’s To pics Foundation Framework NSArray, NSDictionary, NSSet NSUserDefaults, etc. Objective-C Protocols and Delegates Memory Management Allocating and initializing objects Reference Counting Demo! Wednesday, April 7, 2010
Background image of page 4
NSArray NSArray Ordered collection of objects Cannot be modiFed once created Important methods: - (int)count - (id)objectAtIndex:(int)index - (void)makeObjectsPerformSelector:(SEL)aSelector - (NSArray *)sortedArrayUsingSelector:(SEL)aSelector NSMutableArray ModiFable version of NSArray - (void)addObject:(id)object - (void)insertObject:(id)object atIndex:(int)index - (void)removeObjectAtIndex:(int)index - (void)replaceObjectAtIndex:(int)index withObject:(id)object Wednesday, April 7, 2010
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
NSDictionary NSDictionary Cannot be modifed once created! Look up a value using a key (aka a “hash table”) A key must implement - (NSUInteger)hash and - (BOOL)isEqual:(NSObject *)obj Usually keys are NSString objects (since that implements those two) Important methods: - (int)count - (id)objectForKey:(id)key - (NSArray *)allKeys - (NSArray *)allValues NSMutableDictionary Modifable version oF NSDictionary - (void)setObject:(id)object forKey:(id)key - (void)removeObjectForKey:(id)key - (void)addEntriesFromDictionary:(NSDictionary *)dictionary Wednesday, April 7, 2010
Background image of page 6
NSSet NSSet Unordered collection of objects without duplicates Cannot be modiFed once created Important methods: - (int)count - (BOOL)containsObject:(id)object - (id)anyObject - (void)makeObjectsPerformSelector:(SEL)aSelector - (id)member:(id)object (uses isEqual: and returns a matching object) NSMutableSet ModiFable version of NSSet - (void)addObject:(id)object - (void)removeObject:(id)object - (void)unionSet:(NSSet *)otherSet - (void)minusSet:(NSSet *)otherSet - (void)intersectSet:(NSSet *)otherSet Wednesday, April 7, 2010
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
NSArray of NSString objects NSArray *myArray = . ..; // known to only have NSString objects inside for (NSString *string in myArray) { double value = [string doubleValue]; // crash if not NSString } NSArray of id NSArray *myArray = . ..; // no idea what kind of objects are inside for (id obj in myArray) { < do something with obj here, but make sure you don’t send it a message it doesn’t respond to > if ([obj isKindOfClass:[NSString class]]) { // send NSString messages to obj with impunity! } } Wednesday, April 7, 2010
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 36

Lecture 04_0 - CS193p Spring 2010 Wednesday, April 7, 2010...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online