Upload
sujith-krishnan
View
1.256
Download
2
Embed Size (px)
DESCRIPTION
Citation preview
More than UI
Sujith Krishnan
30SS
Foundation framework
• Common Classes
– String NSString NSMutableString
– Array NSArray NSMutableArray– Dictionary NSDict.. NSMutableDict..– File Handling NSFileManager– Persistance NSKeyedArchiver– Thread NSThread– Timer NSTimer– XML NSXmlParser– HTTP Connection NSURLReqest
Collections – Array & Dictionary
• Retain the objects
• Available as mutable and immutable
• Direct persistence – writeToFile
• Generic – can hold any objects
Autorelease ???
• Framework take care of releasing the object
• Factory methods are autorelease methods
• Can call autorelease on any object
• Write methods which will return autorelease objects
Autorelease pool
• Pool of autorelease objects
• Restrict the scope of autorelease objects
• Must to use in thread methods
• Call retain to extend the scope of variable-(void)anyMethod{
NSAutoreleasePool *pool = [[NSAuto…
// allocate a lot of memory (autorelease)
[pool release];
}
Autorelease - A Scenario
(NSString*)someMethod{NSString *stringToReturn = nil;for (int i = 0; i < someLargeNumber; i++) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *string = ...;string = [string stringByAppendingString:...];if ([string someCondition]) {
stringToReturn = [string retain];}[pool release];if (stringToReturn)
break;}return [stringToReturn autorelease];
}
Persistence
• Saving object state to a file
• Should implement encoding methods• Key – Value• NSKeyedArchiver• NSKeyedUnarchiver
• Save in document directory
• Can use SQLite3 also
• \tmp– temporary files used by f/w
• \Documents– user files
• \Library– application preferences, settings etc..
Application Directories
Typical NSThread Use Case- (void)someAction:(id)sender{
// Fire up a new thread[NSThread detachNewThreadSelector:@selector(doWork:)
withTarget:self object:someData];}
- (void)doWork:(id)someData{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];[someData doLotsOfWork];// Message back to the main thread[self performSelectorOnMainThread:@selector(allDone:)
withObject:[someData result] waitUntilDone:NO];[pool release];
}
Delegates
• Define delegate methods– @required & @optional
• Multiple object and single delegate definition– Object comparison– Use of tag
Accelerometer - Hints
Format Specifiers
• Same as what we use for rest of OOP
• %@ - for NSString , Object , Date etc…
• Can use positional specifiers
• IEEE print specifications