November 2013
Beginner
325 pages
9h 47m
English
Programmers often need to loop and perform operations on each item in an array (or “iterate over an array”). You can do this with a for-loop. Edit main.m:
#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 all three
NSArray *dateList = @[now, tomorrow, yesterday];
// Print a couple of dates
NSLog(@"The first date is %@", dateList[0]);
NSLog(@"The third date is %@", dateList[2]);
// How many dates are in the array?
NSLog(@"There are %lu ...Read now
Unlock full access