12
More than UI Sujith Krishnan 30SS

More than UI

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: More than UI

More than UI

Sujith Krishnan

30SS

Page 2: More than UI

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

Page 3: More than UI

Collections – Array & Dictionary

• Retain the objects

• Available as mutable and immutable

• Direct persistence – writeToFile

• Generic – can hold any objects

Page 4: More than UI

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

Page 5: More than UI

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];

}

Page 6: More than UI

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];

}

Page 7: More than UI

Persistence

• Saving object state to a file

• Should implement encoding methods• Key – Value• NSKeyedArchiver• NSKeyedUnarchiver

• Save in document directory

• Can use SQLite3 also

Page 8: More than UI

• \tmp– temporary files used by f/w

• \Documents– user files

• \Library– application preferences, settings etc..

Application Directories

Page 9: More than UI

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];

}

Page 10: More than UI

Delegates

• Define delegate methods– @required & @optional

• Multiple object and single delegate definition– Object comparison– Use of tag

Page 11: More than UI

Accelerometer - Hints

Page 12: More than UI

Format Specifiers

• Same as what we use for rest of OOP

• %@ - for NSString , Object , Date etc…

• Can use positional specifiers

• IEEE print specifications