(1) Cocoa Toch Frameworks
Foundation
- Object wrappers
- Strings,collections
- Various system services (file I/O and network)
- Subset of Foundation on Mac
UIKit
- Event handling
- Graphics and windowing
- Text and web management
(2) Foundation
- Strings
NSString *myString = @"This is a string";
NSString *myString = [NSString stringWithFormat:@"%d techTalks",24];
NSString *pathString = @"Library/Caches/Images/dataCache.txt";
NSArrary *pathComments = [pathString pathComments];
NSString *fileName = [pathString lastPathComponent];
NSString *fileContents = [NSString stringWithContentOfFile:pathString];
- Arrays
- Mutable
NSMutableArray *arr = [NSMutableArray array];
[arr addObject:@"randomString"];
- Immutable
NSArray *arr = [NSArray arrayWithObjects:@"foo",@"bar",@"moof",nil];
NSString *complexString = [arr componentsJoinedByString:@"--"];
- Mutable
- Dictionary
- Mutable
NSMutableDictionary *md = [NSMutableDictionary dictionaryWithCapacity:5];
[md setObject:@"randomValue" forKey:@"randomKey"]; - Immutable
NSDictionary *dict = [NSDictionary dictionaryWithObjectAndKeys:
@"valueOne",@"keyOne",@"valueTwo",@"keyTwo",nil];
- Mutable
- File I/O
- NSFileManager class
NSFileManager *fm = [NSFileManager defaultManager];
if ([fm isWritableFileAtPath: path]) {
[fm createFileAtPath: [path stringByAppendingPathComponent:@"foo.bar"]
contents:@"foo"
attributes:nil ];
} - tmp directory -- Cleared,not backed up
- Library/Caches -- Saved,not backed up
- Everything else -- Backed up
- NSFileManager class
- NSLog
- NSLog(@"Simple debug statement");
- NSLog(@"There are %d North American Tech Talk",numberOfNATechTalks);
- NSLog(@"Got an array: %@",myArray);
- NSLog(@"Got an dictionary: %@",myDictionary);
(3) Foundation Bundles -- a special kind of folder
- Executable
- User Interface (nib) files
- Metadata
- Resources
- Access via NSBundle class
- Easy accesses to static resources
- Images
- Sounds
- Default data
- Read-only
- Codesigning requires static bundle
- Write new data to sandbox
- Accessing resources
// Get an image from the main app bundle
NSBundle *appBundle = [NSBundle mainBoundle];
NSString *imagePath = [appBundle pathForResource:@"logo" ofType:@"png"];
UIImage *logoImg = [[UIImage alloc] initWithContentsOfFile: imagePath];
// Load a default SQLite DB if no user data exists
NSString *defaultDB = [appBoundle pathForResource:@"db" ofType:@"sql"];
if (sqlite3_open([defaultDB UTF8String],&database) == SQLITE_OK) {
// fetch data from default db
}
(4) Foundation -- Networking
- Standard sockets programming
- CFNetwork,CFSocket
- POSIX
- NSURLConnection
- Asynchronous request loading
- NSXML
- Basic parser
- Bonjour Networking
- Zero-configuration discovery
- Bonjour discovery
(5) UIKit -- The UIKit Library,
- Buttons and Controls
- Image Views
- Web Views (put Safari inside your application)
(6) Application Design Patterns
- Model-View-Controller
- Foundation is for Model
- UIKit is for View
- iPhone SDK has ViewController class for Controller
- MVC is the umbrella design pattern
(7) Application Design Patterns - Target-Action
(8) Application Design Patterns - Notification
- Notification Center
- Observer / Controller
- Notifications -- Registering an observer
MPMoviePlayerController *mpc;
NSURL *url = [NSURL urlWithString:@"http://foo.com/movie.mov"];
mpc = [[MPMoviePlayerController alloc] initWithContentURL:url];
// Register for device notifications
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(movieLoaded:)
name: MPMoviePlayerContentPreloadDidFinishNotification
object:mpc];
// Get preload notification and react accordingly
- (void) movLoaded: (NSNotification *) notif {
[(MPMoviePlayerController *)[notif object] play];
}
(9) Application Design Patterns - Delegation
- The Application Life Cycle
- Application launch
- UIApplication
- Main nib
- Main window
- Application delegate
- UI config
- UIApplication
- Application launch
- The Application Delegate
- Your first (and last) chance to act
- Custom class written by you
- Conforms to UIApplicationDelegate protocol
- Hooked up in interface Builder
- Two key methods
-
- (void) applicationDidFinishLaunching:(UIApplication*) app
- Load initial UI,prepare saved state
-
- (void) applicationWillTerminate:(UIApplication*) app
- Save state and data
-
- (void) applicationDidFinishLaunching:(UIApplication*) app
- Your first (and last) chance to act
- Delegate Design Pattern
- Customization without subclassing
- Fine-tune default behavior
- Respond to user actions
- Separate controller from view
- Customization without subclassing
(10) iPhone Design Patterns
- Model-View-Controller
- Target-Action
- what reacts,and how
- dynamic object and selector
- Notification
- information while app is running
- Asynchronous delivery
- Delegation
- Direct control over view behavior
- Synchronous delivery and response
- Target-Action
(11) iPhone Development
- Get to know Cocoa Touch
- Understand the Objective-C runtime
- Explore Fundation and UIKit
- Embrace design pattern
- Look at example nib file
- Use NSLog
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。