Sunday, September 5, 2010

Arrays in XCODE 3.2.3 and IPHONE SDK 4

How to create an Array:

To create an Array with the name testArray do the following:

NSArray *testArray = [[NSArray alloc] init];

The Array called  an empty array.

Add something to the array
[testArray addObject:someObject];
[testArray addObject:someOtherObject];

// Get stuff out of the array
NSObject *anObject = [testArray objectAtIndex:0];

// Loop through contents of array
for (NSObject *anObject in testArray) {
     
}

// Remove from array
[testArray removeObjectAtIndex:1];

No comments:

Post a Comment