Accessing arrays
Arrays are ordered lists, and you access an item in an array by its index.
Arrays are zero-based: the first item is stored at index 0
, the second item is stored at index 1
, and so on.
You can access an individual item in the array using the name of the array followed by the index of the item in square brackets. Add the following code to your program to access and print two items in the array:
#import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { // Create three NSDate objects NSDate *now = [NSDate date]; NSDate *tomorrow = [now dateByAddingTimeInterval:24.0 * 60.0 * 60.0]; NSDate *yesterday = [now dateByAddingTimeInterval:-24.0 * 60.0 * 60.0]; // Create an array containing ...
Get Objective-C Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.