#pragma mark ----------不可变数组
NSArray *array1 = [[NSArray alloc]initWithObjects:@"重庆",@"asdf", nil];
NSLog(@"%@",array1);
NSArray *array2 = [NSArray arrayWithArray:array1];
NSLog(@"array2 = %@",array2);
NSUInteger n = [array2 count];
NSLog(@"n = %lu",n);
NSLog(@"%@",[array2 objectAtIndex:1]);
NSLog(@"%lu",[array2 indexOfObject:@"重庆"]);
NSArray *array3 = @[@"1",@"2",@"3"];
NSLog(@"%@",array3[2]);
#pragma mark ---------------可变数组
NSMutableArray *marray = [NSMutableArray array];
NSLog(@"%@",marray);
NSMutableArray *marray2 = nil;
NSLog(@"marray2 = %@",marray2);
[marray addObject:@"hahah"];
[marray addObject:@"hahah"];
[marray addObject:@"hahah"];
[marray addObject:@"hahah"];
[marray addObject:@"hahah"];
[marray addObject:@"biubiubiu"];
NSLog(@"marray = %@",marray);
[marray insertObject:@"40" atIndex:0];
NSLog(@"marray = %@",marray);
[marray exchangeObjectAtIndex:1 withObjectAtIndex:2];
NSLog(@"marray = %@",marray);
[marray replaceObjectAtIndex:0 withObject:@"bengbeng"];
NSLog(@"marray = %@",marray);
[marray removeObject:@"biubiu"];
NSLog(@"marray = %@",marray);
[marray removeLastObject];
NSLog(@"marray = %@",marray);
[marray removeObjectAtIndex:2];
[marray removeObject:@"hahah"];
NSLog(@"marray = %@",marray);
[marray removeAllObjects];
NSLog(@"marray = %@",marray);
Book *b1 = [Book bookWithName:@"数据结构" price:20.00];
Book *b2 = [Book bookWithName:@"计算机组成" price:23.00];
Book *b3 = [Book bookWithName:@"计算机网络" price:27.00];
Book *b4 = [Book bookWithName:@"深入内核" price:25.00];
Book *b5 = [Book bookWithName:@"网络管理" price:24.00];
Book *b6 = [Book bookWithName:@"网络安全" price:22.00];
NSMutableArray *libray = [NSMutableArray arrayWithObjects:b1,b2,b3,b4,b5,b6, nil];
NSString *searchName = @"网络管理";
for (int i = 0; i < libray.count; i++) {
Book *b = libray[i];
if ([[b name] isEqualToString:searchName]) {
[b setPrice:50];
[b introduce];
}
}
for (int i = 0; i < libray.count; i++) {
Book *b = libray[i];
[b introduce];
}
Book *newbook = [Book bookWithName:@"资本论" price:99.99];
[libray addObject:newbook];
NSLog(@"%@",libray);
[libray removeObject:@"数据结构"];
#pragma mark ---------NSNumber NSValbe
NSNumber *number = [NSNumber numberWithInt:10];
NSLog(@"%@",number);
NSNumber *numb1 = [NSNumber numberWithFloat:19.99];
NSLog(@"%@",numb1);
float n1 = [numb1 floatValue];
NSLog(@"%.3f",n1);
NSRange range = NSMakeRange(1, 2);
NSValue *value = [NSValue valueWithRange:range];
}
}