NSArray *myArray = [NSArrayarrayWithObjects:string1, string2, string3, nil];
for (NSString *obj in myArray) {
NSLog(@"%@",obj);
}
for (NSString *obj in [myArrayreverseObjectEnumerator])
{
NSLog(@"%@",obj);
}
NSArray *arr1 = [NSArrayarrayWith Objects:@"iPhone", @"iPod",nil];
NSDictionary *myDict = [[NSDictionar y alloc] ?dictionaryWithObjectsAndKeys: arr1, @"mobile", arr2, @"computers", nil];
for (id key in myDict) {
NSLog(@"key: %@, value: %@",
? key, [myDictobjectForKey:
? key]);
}
[myDict setObject:string2 forKey:@"media"];
NSNotification
Notifications provide a handy way for youto pass information between objects in your application without needing a direct reference between them. which contains a name, an object (often the object posting the notification), and an optional dictionary.
登记消息、消息处理方法、注销
[[NSNotificationCenterdefaultCenter] addObserver:self selector:@selector(doSomething:)
? name:@"myNotification"
?object:nil];
-(void)deallc
{
[[NSNotificationCenterdefaultCenter] removeObserver:self];
[superdealloc];
}
-(void)doSomething:(NSNotification*)aNote
{
NSDictionary *myDict = [aNoteobject];
NSLog(@”%@”, myDict);
}
发送消息
[[NSNotificationCenterdefaultCenter] postNotificationName:MY_NOTIFICATION?object:myDict];
内存管理
iOS不支持GC,因此必须手动释放创建的对象[注意是创建者负责释放,像工厂方法的对象不需要调用者释放]
[object release];
Remember this basic rule of thumb: Any time you call the alloc, copy, or retainmethods on an object, you must at some point later call the release method.