集合 - 1

来源:互联网 发布:linux在终端中打开rpm 编辑:程序博客网 时间:2024/04/30 10:29

Cocoa 中的集合有NSArray(NSMutableArray), NSSet (NSMutableSet, NSCountedSet), NSDictionary (NSMutableDictionary)

 

NSArray

-(unsigned) count

-(id) objectAtIndex:(unsigned) index

-(BOOL) containsObject:(id) anObject

 

NSMutableArray

-(void) addObject:(id) anObject

-(void) insertObject:(id) anObject atIndex:(unsigned) index

-(void) removeObjectAtIndex:(unsigned) index

-(void) removeObject:(id) object

 

NSDictionary

-(unsigned) count

-(id) objectForKey:(id) aKey

-(NSArray *) allKeys

 

NSMutableDictionary

-(void) setObject:(id) anObject forKey:(id) aKey

-(void) removeObjectForKey:(id) aKey

 

//操作plist

-(id) initWithContentsOfFile:(NSString *) aPath

-(BOOL) writeToFile:(NSString *) path atomically:(BOOL) flag

 

 获取地址簿记录 (加入AddressBook 框架)

#import <AddressBook/AddressBook.h>

 

ABAddressBook * book = [ABAddressBook sharedAddressBook];

NSArray *people = [book people];

NSString *firstName = [people valueForProperty:@"First"];

NSString *lastName = [people valueForProperty:@"Last"];

 

原创粉丝点击