<span style="font-size:18px;"> :</span>
<span style="font-size:18px;">(1) . (2) , .(3) (4) ,
//1.
//(1)
//arrayWithObjects , , , ,
//nil . nil ,
NSArray *array1 = [NSArray arrayWithObjects:@"Love", @"Summer", @"Angle", @"Sunshine", @"Sunshine", nil];
NSLog(@"array1 = %@", array1);
//(2)
NSArray *array2 = [[NSArray alloc] initWithObjects:@"Love", @"Summer", @"Sunshine", nil];
NSLog(@"array2 = %@", array2);
//2.
NSUInteger count = [array1 count];
NSLog(@"count = %ld", count);
//3.
//(1)
NSString *str1 = [array1 objectAtIndex:1];
NSLog(@"str1 = %@", str1);
//(2)
//firstObject lastObject objectAtIndex: , nil objectAtIndex: crash . index 0 beyond bounds of empty array
NSString *str2 = [array1 objectAtIndex:1];
NSLog(@"str2 = %@", str2);
NSString *firstObject= [array1 firstObject];
NSLog(@"firstObject = %@", firstObject);
//(3)
NSString *lastObject = [array1 lastObject];
NSLog(@"lastObject = %@", lastObject);
//4.
NSUInteger index = [array1 indexOfObject:@"Sunshine"];
NSLog(@"index = %lu", index);
//5.
BOOL isExist = [array1 containsObject:@"Angle"];
NSLog(@"isExist = %d", isExist);
//6. ( )
NSArray *sortArr = [array1 sortedArrayUsingSelector:@selector(compare:)];
NSLog(@"sortArr = %@", sortArr);
//7. ( )
//
for (int i = 0; i < [array1 count]; i++) {
NSString *str = [array1 objectAtIndex:i];
NSLog(@"%@", str);
}
/**
* forin .( ), ,
type *object //type
//object ( )
collection : ( , , , )
*/
for (NSString *str in array1) {
NSLog(@"%@", str);
}
//8.
NSMutableArray *array3 = [[NSMutableArray alloc] initWithObjects:@"Summer", @"Sunshine", @"Angle", @"Cindy", nil];
NSLog(@"%@", array3);
//9.
[array3 removeLastObject];
NSLog(@"%@", array3);
[array3 removeObjectAtIndex:1];
NSLog(@"%@", array3);
[array3 removeObject:@"Summer"];
NSLog(@"%@", array3);
//10.
NSArray *newArr = [array1 arrayByAddingObject:@"Angle"];
NSLog(@"newArr = %@", newArr);
//11.
NSMutableArray *mutableArray = [NSMutableArray array];
[mutableArray addObject:@"Love"];
NSLog(@"mutableArray, = %@", mutableArray);
//12.
[mutableArray setArray:array1];
NSLog(@"mutableArray = %@",mutableArray);
//13.
[mutableArray addObjectsFromArray:array1];
NSLog(@"mutableArray, = %@", mutableArray);
//14.
[mutableArray replaceObjectAtIndex:1 withObject:@"lala"];
NSLog(@"mutableArray = %@",mutableArray);
//15.
[mutableArray exchangeObjectAtIndex:0 withObjectAtIndex:2];
NSLog(@"mutableArray = %@",mutableArray);
//16.
[mutableArray insertObject:@"xxx" atIndex:1];
NSLog(@"mutableArray = %@",mutableArray);
//17. ,
[array3 sortUsingSelector:@selector(compare:)];
NSLog(@"array3 = %@", array3);
//18.
// , , ,id ,
for (NSString *str in array3) {
NSLog(@"str = %@", str);
}
//19.
[mutableArray removeAllObjects];
NSLog(@"mutableArray = %@",mutableArray);
//NSNumber
// long long
NSLog(@"%lu", sizeof(long long ));
//1.
char a = 'f';
int b = 120;
// @120;// NSNumber
// @"120";// ,NSString
short c = 100;
long d = 1000;
float e = 10.2;
double f = 12.25;
BOOL isTure = YES;
//2. NSNumber
NSNumber *a1 = [NSNumber numberWithChar:a];
NSLog(@"%@", a1);
NSNumber *a2 = [NSNumber numberWithInt:b];
NSLog(@"%@", a2);
NSNumber *a3 = [NSNumber numberWithShort:c];
NSLog(@"%@", a3);
NSNumber *a4 = [NSNumber numberWithLong:d];
NSLog(@"%@", a4);
NSNumber *a5 = [NSNumber numberWithFloat:e];
NSLog(@"%@", a5);
NSNumber *a6 = [NSNumber numberWithDouble:f];
NSLog(@"%@", a6);
NSNumber *a7 = [NSNumber numberWithBool:isTure];
NSLog(@"%@", a7);
// :
NSArray *arr = [NSArray arrayWithObjects:a1, a2, a3, a4, a5, a6, a7,nil];
NSLog(@"%@",arr);
// :
NSArray *arr1 = @[a1, a2, a3, a4, a5, a6, a7];
NSLog(@"%@",arr1);
//3. NSNumber
char a10 = [a1 charValue];
NSLog(@"%c", a10);
int a11 = [a2 intValue];
NSLog(@"%d", a11);
//4.NSNumber
NSLog(@"%ld",[a1 compare:a2]);
</span>