#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
// insert code here...
//Array A
NSArray *myArraya = @[@"China",@"USA",@"France"];
NSLog(@"The Array A is %@", myArraya);
//Array B
NSDate *datea = [NSDate date];
sleep(2);
NSDate *dateb = [NSDate date];
sleep(2);
NSDate *datec = [NSDate date];
NSArray *myArrayb = @[datea, dateb, datec];
NSLog(@"The Array B is %@", myArrayb);
NSLog(@"The first value of array b is %@", myArrayb[0]);
NSLog(@"The third value of array b is %@", myArrayb[2]);
NSLog(@"The count num of array b is %lu", [myArrayb count]);
//*遍历数组的值
for(int i = 0; i < [myArrayb count]; i++){
NSDate *d = myArrayb[i];
NSLog(@"The date is %@", d);
}
//*遍历数组的值-方法2
for(NSDate *dd in myArrayb){
NSLog(@"The second date is %@", dd);
}
//数组3 NSMutableArray
NSDate *today = [NSDate date];
NSDate *yesterday = [today dateByAddingTimeInterval:-24*60*60];
NSDate *tomorrow = [today dateByAddingTimeInterval:24*60*60];
NSMutableArray *myArrayC = [NSMutableArray array];
[myArrayC addObject:today];
[myArrayC addObject:tomorrow];
NSLog(@"My Array C is : %@", myArrayC);
[myArrayC insertObject:yesterday
atIndex:0];
for(NSDate *dc in myArrayC){
NSLog(@"The Array C is : %@",dc);
}
[myArrayC removeObjectAtIndex:0];
NSLog(@"The Array C has updated to : %@", myArrayC);
}
return 0;
}
Result:
2018-03-11 00:36:18.490239+0800 TOCNSArraya[62051:14140071] The Array A is (
China,
USA,
France
)
2018-03-11 00:36:22.503433+0800 TOCNSArraya[62051:14140071] The Array B is (
"2018-03-10 16:36:18 +0000",
"2018-03-10 16:36:20 +0000",
"2018-03-10 16:36:22 +0000"
)
2018-03-11 00:36:22.503532+0800 TOCNSArraya[62051:14140071] The first value of array b is Sun Mar 11 00:36:18 2018
2018-03-11 00:36:22.503583+0800 TOCNSArraya[62051:14140071] The third value of array b is Sun Mar 11 00:36:22 2018
2018-03-11 00:36:22.503603+0800 TOCNSArraya[62051:14140071] The count num of array b is 3
2018-03-11 00:36:22.503689+0800 TOCNSArraya[62051:14140071] The date is Sun Mar 11 00:36:18 2018
2018-03-11 00:36:22.503736+0800 TOCNSArraya[62051:14140071] The date is Sun Mar 11 00:36:20 2018
2018-03-11 00:36:22.503760+0800 TOCNSArraya[62051:14140071] The date is Sun Mar 11 00:36:22 2018
2018-03-11 00:36:22.503798+0800 TOCNSArraya[62051:14140071] The second date is Sun Mar 11 00:36:18 2018
2018-03-11 00:36:22.503811+0800 TOCNSArraya[62051:14140071] The second date is Sun Mar 11 00:36:20 2018
2018-03-11 00:36:22.503823+0800 TOCNSArraya[62051:14140071] The second date is Sun Mar 11 00:36:22 2018
2018-03-11 00:36:22.504032+0800 TOCNSArraya[62051:14140071] My Array C is : (
"2018-03-10 16:36:22 +0000",
"2018-03-11 16:36:22 +0000"
)
2018-03-11 00:36:22.504102+0800 TOCNSArraya[62051:14140071] The Array C is : Sat Mar 10 00:36:22 2018
2018-03-11 00:36:22.504122+0800 TOCNSArraya[62051:14140071] The Array C is : Sun Mar 11 00:36:22 2018
2018-03-11 00:36:22.504180+0800 TOCNSArraya[62051:14140071] The Array C is : Mon Mar 12 00:36:22 2018
2018-03-11 00:36:22.504330+0800 TOCNSArraya[62051:14140071] The Array C has updated to : (
"2018-03-10 16:36:22 +0000",
"2018-03-11 16:36:22 +0000"
)
Program ended with exit code: 0