Objective-C Foundation Objects

BOOL

Boolean type

flag = YES;
if (flag != NO) { 
 ...
}

if (flag) {
  ...
}

Foundation Objects

To include the foundation objects

#import <Foundation/Foundation.h>

NSArray

Create & access an array of Objective-C objects

NSArray *numbers = [NSArray arrayWithObjects: @"One", @"Two", @"Three", nil];
NSString *value = [numbers objectAtIndex: 2];   // "Three"
count = [numbers count];

NSMutableArray is the mutable corresponding of NSArray

NSString

  • String using Unicode used for iOS API
  • @"my value" creates a NSString instead of (char *)
  • NSString is immutable

NSMutableString is the mutable corresponding of NSString

Collection

NSDictionary

  • Heap structure with values lookup from a key
  • Immutable

NSMutableDictionary is the mutable corresponding of NSDictionary

Retrieve objects stored in NSDictionary

for (id key in collection) {
   id obj = [collection objectForKey:key];
}

NSSet

  • Unordered collection of unique value
  • Immutable

Add an object to a set

[mySet addObject:obj];

NSMutableSet is the mutable corresponding of NSSet

Enumerate Collection

Enumerate over a collection

NSArray *array = ...;
for (NSString *value in array) {
    [value ...];
}

Enumerate over key

NSDictionary *collection = ...;
for (id key in collection) {
  [key ...];
}

NSUserDefaults

Lightweight storage of Property Lists that persists between application launches

Other Foundation Framework Objects

Type  
NSNumber Object wrapper for int, float, double, BOOL
NSValue Wrapper for non-object data type
NSData Store raw data
NSDate Store time value