标签:
NSMutableArray *arr = [NSMutableArray array];
NSMutableArray *arr2 = [[NSMutableArray alloc] initWithCapacity:5];
NSMutableArray *arr3 = [NSMutableArray arrayWithObjects:@"1",@"2", nil];
NSMutableArray *arr4 = [[NSMutableArray alloc] initWithObjects:@"1",@"2", nil];
- (void)addObject:(id)object;
- (void)addObjectsFromArray:(NSArray *)array;
- (void)insertObject:(id)anObject atIndex:(NSUInteger)index;
- (void)removeLastObject;
- (void)removeAllObjects;
- (void)removeObjectAtIndex:(NSUInteger)index;
- (void)removeObject:(id)object;
- (void)removeObjectsInRange:(NSRange)range;
- (void)replaceObjectAtIndex:(NSUInteger)index withObject:(id)anObject;
- (void)exchangeObjectAtIndex:(NSUInteger)idx1 withObjectAtIndex:(NSUInteger)idx2;
NSMutableArray *array = @[@"lnj", @"lmj", @"jjj"];
// 报错, 本质还是不可变数组
[array addObject:@“Peter”];
+ (instancetype)dictionary;
+ (instancetype)dictionaryWithObject:(id)object forKey:(id <NSCopying>)key;
+ (instancetype)dictionaryWithObjectsAndKeys:(id)firstObject, ...;
+ (id)dictionaryWithContentsOfFile:(NSString *)path;
+ (id)dictionaryWithContentsOfURL:(NSURL *)url;
NSDictionary创建简写
objc NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@"lnj", @"name", @"12345678", @"phone", @"天朝", @"address", nil];
objc NSDictionary *dict = @{@"name":@"lnj", @"phone":@"12345678", @"address":@"天朝"};
NSDictionary获取元素简写
objc [dict objectForKey:@"name”];
objc dict[@"name”];
键值对集合的特点
- (NSUInteger)count;
- (id)objectForKey:(id)aKey;
快速遍历
NSDictionary *dict = @{@"name":@"lnj", @"phone":@"12345678", @"address":@"天朝"};
for (NSString *key in dict) {
NSLog(@"key = %@, value = %@", key, dict[key]);
}
[dict enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *obj, BOOL *stop) {
NSLog(@"key = %@, value = %@", key, obj);
}];
将字典写入文件中
示例
NSDictionary *dict = @{@"name":@"lnj", @"phone":@"12345678", @"address":@"天朝"};
BOOL flag = [dict writeToFile:@"/Users/LNJ/Desktop/dict.plist" atomically:YES];
NSLog(@"flag = %i", flag);
NSDictionary *newDict = [NSDictionary dictionaryWithContentsOfFile:@"/Users/LNJ/Desktop/dict.plist"];
NSLog(@"newDict = %@", newDict);
- (void)setObject:(id)anObject forKey:(id )aKey;
- (void)removeObjectForKey:(id)aKey;
- (void)removeAllObjects;
objc [dict setObject:@"Jack" forKey:@"name”];
objc dict[@"name"] = @"Jack";
NSArray和NSDictionary的区别
NSArray的用法
objc @[@"Jack", @"Rose"] (返回是不可变数组)
objc id d = array[1];
objc array[1] = @"jack";
NSDictionary的用法 +创建 objc @{ @"name" : @"Jack", @"phone" : @"10086" } (返回是不可变字典)
objc id d = dict[@"name"];
objc dict[@"name"] = @"jack";
typedef CGPoint NSPoint;
CGPoint的定义
struct CGPoint {
CGFloat x;
CGFloat y;
};
typedef struct CGPoint CGPoint;
typedef double CGFloat;
typedef CGSize NSSize;
CGSize的定义
struct CGSize {
CGFloat width;
CGFloat height;
};
typedef struct CGSize CGSize;
typedef CGRect NSRect;
CGRect的定义
struct CGRect {
CGPoint origin;
CGSize size;
};
typedef struct CGRect CGRect;
标签:
原文地址:http://www.cnblogs.com/zhoudaquan/p/5017747.html