IOS Note - Core NS Data Types

NSString (Immutable)
NSMutableString (rarely used)
NSNumber
NSValue
NSData (bits)
NSDate
NSArray (Immutable)
 - once you create the array, you cannot add or remove objects
 eg:
 NSArray *primaryColors = [NSArray arayWithObjects:@"red", @"yellow", @"blue", nil];
NSMutableArray
 
NSDictionary
 NSDictionary *base = [NSDictionary dictionaryWithObjectsAndKeys:
       [NSNUmber numberWithInt:2], @"binary",
       [NSNUmber numberWIthInt:16], #hexadecimal", nil];
 - (int)count;
 - (id)objectForKey:(id)key;
 - (NSArray *)allKeys;
 - (NSArray *)allValues;

NSMutableDictionary
NSSet
NSMutableSet
NSOrderedSet
NSMutableOrderedSet

 

-----------------------------------------------------------------------------------------------------------

Enumeration

NSArray

NSArray *myArray = ...;
for (NSString *str in myArray) {
    if ([str isKindOfClass:[NSString class]]) {
        double value = [str doubleValue];
    }
}

NSSet

NSSet *mySet = ...;
for (id obj in mySet) {
    if ([obj isKindOfClass:[NSString class]]) {
        // send NSString messages to obj
    }
}

NSDictionary

NSDictionary *myDict = ...;
for (id key in myDict) {
    id value = [myDict objectForKey:key];
}

 

posted @ 2013-12-18 14:46  Master HaKu  阅读(225)  评论(0编辑  收藏  举报