NSArray+Primitive
NSArray+Primitive extends NSArray and NSMutableArray to provide support for primitives
BOOL, char, int, float, CGPoint, CGSize, CGRect
. The following example demonstrates int
but all the other types work the same way.NSMutableArray* array = [NSMutableArray array]; [array addInt:1]; // array = [1] [array addInt:2]; // array = [1, 2] int i = [array intAtIndex:0]; // i = 1 [array swapIndex1:0 index2:1]; // array = [2, 1] [array replaceIntAtIndex:0 withInt:3]; // array = [3, 1] [array insertInt:4 atIndex:1]; NSLog(@"%@", [array description]); // console shows [3, 4, 1]
NSDictionary+Primitive
NSDictionary+Primitive extends NSDictionary and NSMutableDictionary to provide support for primitives
BOOL, char, int, float, CGPoint, CGSize, CGRect
. The following example demonstrates int
but all the other types work the same way.NSMutableDictionary* dict = [NSMutableDictionary dictionary]; [dict setInt:1 forKey:@"int1"]; // dict = { int1:1 } [dict setInt:2 forKey:@"int2"]; // dict = { int1:1, int2:2 } int i = [dict intForKey:@"int1"]; // i = 1 NSLog(@"%@", [dict description]); // console shows { int1 = 1; int2 = 2; }
No comments:
Post a Comment