User Tools

Site Tools


Common Data Structures

Each of the following three data structures, as written, cannot be changed once made (they are immutable). To use the editable versions, prepend Mutable before the class name: NSMutableString, NSMutableArray, NSMutableDictionary.


Stores objects in a list, fetching them by their position in the list, known as index.

Cannot store primitives. Resizes itself automatically.

Common methods:

  1. objectAtIndex:- returns the object at the given index
  2. count- returns the number of elements in the array
  3. insertObject:atIndex- puts the given object at the given index, replacing what was there
  4. addObject:- adds the given object at the end of the array


AKA map, hash, associative array, keyed array.

Pairs keys to objects (like dictionary definitions paired to dictionary words).

No guarantees about the order of keys or objects within dictionary. Keys must implement Comparable (must be unique and comparable) by overriding equalTo: method. Strings are commonly used as keys. Cannot have duplicate keys (can have duplicate objects)

Common methods:

  1. objectForKey:- returns object stored under a given key. Returns nil if key not found
  2. setObject:forKey:- assigns the given object to the given key. Replaces key if previously present.
  3. allKeys- returns all keys in dictionary
  4. count- returns number of key/object pairings


Wrapper class for strings. A collection of characters stored in order.

Literal strings are represented with


which can be assigned to any NSString variable.

Common Methods:

  1. [NSString stringWithFormat:@“STRING %i”, 4]: used to create strings by substituting variables inline with text using string substitutions (%d, %s, %@ for int, char, objective-c object). example creates a string “STRING 4”.
  2. intValue- returns the string converted to an integer
ios-labs-s14/basics-structs.txt · Last modified: 2014/02/26 13:06 by mbarboi