32. but how to solve this ?
- (Person*) getChild {
Person* child = [[Person alloc] init];
[child setName:@”xxxx”];
....
// will return ... [child release] or not ?
return child;
}
34. That’s why create pool
first ...
int main(int argc, char* argv[]) {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
// put your own code here ...
[pool release];
}
35. how to solve this ?
- (Person*) getChild {
Person* child = [[Person alloc] init];
[child setName:@”xxxx”];
....
// will return ... [child release] or not ?
return [child autorelease];
}
36. Autorelease Pool
•
• NSMutableArray pool
• autorelease Array
• pool Array
release
• autorelease pool
autorelease
pool pool
37. Autorelease Pool Stack
NSAutoreleasePool* poolFirst ..
for (int i=0; i < 10000; i++) {
NSAutoreleasePool* poolSecond ...
// have some autorelease object
// [object autorelease]
[poolSecond release];
}
// other code
[poolFirst release];
38. Autorelease Pool
•
• NSAutoreleasePool
• alloc release
• Autorelease pool retain
autorelease [pool retain] or [pool autorelease]
• AutoreleasePool “
”
• pool pool
iphone
release autorelease
52. iPhone Application
• &
• MVC
• Views (design & life cycle)
• Navigation based & Tab Bar based application
• very important TableView
•
• Web service
53.
54. UIApplication
• Every application must have exactly one instance of
UIApplication (or a subclass of UIApplication). When
an application is launched, the UIApplicationMain
function is called; among its other tasks, this
function create a singleton UIApplication object.
• The application object is typically assigned a
delegate, an object that the application informs of
significant runtime events—for example, application
launch, low-memory warnings, and application
termination—giving it an opportunity to respond
appropriately.
55.
56.
57. UIApplicationMain
• delegateClassName
• Specify nil if you load the delegate object
from your application’s main nib file.
• from Info.plist get main nib file
• from main nib file get the application’s
delegate
77. UINavigationController
• manages the currently displayed screens using the
navigation stack
• at the bottom of this stack is the root view controller
• at the top of the stack is the view controller currently
being displayed
• method:
• pushViewController:animated:
• popViewControllerAnimated:
85. UITabBarController
• implements a specialized view controller that
manages a radio-style selection interface
• When the user selects a specific tab, the tab
bar controller displays the root view of the
corresponding view controller, replacing any
previous views
• init with an array (has many view controllers)
91. TableView
• display a list of data
• Single column, multiple rows
• Vertical scrolling
• Powerful and ubiquitous in iPhone
applications
92.
93.
94. Display data in Table View
•
• Table views display a list of data, so use an array
• [myTableView setList:myListOfStuff];
•
• All data is loaded upfront
• All data stays in memory
•
• Another object provides data to the table view
• Not all at once
• Just as it’s needed for display
• Like a delegate, but purely data-oriented
116. Property Lists
• Convenient way to store a small amount of data
• Arrays, dictionaries, strings, numbers, dates, raw data
• Human-readable XML or binary format
• NSUserDefaults class uses property lists under the hood
• When Not to Use Property Lists
• More than a few hundred KB of data
• Custom object types
• Multiple writers (e.g. not ACID)
120. SQLite
• Complete SQL database in an ordinary file
• Simple, compact, fast, reliable
• No server
• Great for embedded devices
• Included on the iPhone platform
• When Not to Use SQLite
• Multi-gigabyte databases
• High concurrency (multiple writers)
• Client-server applications
121.
122. SQLite Obj-C Wrapper
• http://code.google.com/p/flycode/source/browse/
trunk/fmdb
• A query maybe like this:
• [dbconn executeQuery:@"select * from call"]
123.
124. Using Web Service
• Two Common ways:
• XML
• libxml2
• Tree-based: easy to parse, entire tree in memory
• Event-driven: less memory, more complex to manage state
• NSXMLParser
• Event-driven API: simpler but less powerful than libxml2
• JSON
• Open source json-framework wrapper for Objective-C
• http://code.google.com/p/json-framework/
127. iPhone Application
• &
• MVC
• Views (design & life cycle)
• Navigation based & Tab Bar based application
& TableView
• (sandbox, property list,
sqlite)
• Web service
128. • Objective-C
• The iPhone Developer’s Cookbook
• Programming in Objective-C 2.0
•
• Stanford iPhone dev course
• iTunes iTune Store cs193p
mac windows