User Tools

Site Tools



This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
ios-labs-s14:basics-structs [2014/02/13 21:07]
mbarboi created
ios-labs-s14:basics-structs [2014/02/26 13:06] (current)
Line 1: Line 1:
-NSArray +=====Common Data Structures===== 
-NSDictionary +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:
 +  -objectAtIndex:​- returns the object at the given index
 +  -count- returns the number of elements in the array
 +  -insertObject:​atIndex- puts the given object at the given index, replacing what was there
 +  -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:
 +  -objectForKey:​- returns object stored under a given key. Returns nil if key not found
 +  -setObject:​forKey:​- assigns the given object to the given key. Replaces key if previously present.
 +  -allKeys- returns all keys in dictionary
 +  -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:
 +  -[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".
 +  -intValue- returns the string converted to an integer
ios-labs-s14/basics-structs.1392347231.txt.gz · Last modified: 2014/02/13 21:07 by mbarboi