@property(nonatomic, copy)NSString *name;
- (id)initWithName:(NSString *)name;
@property(nonatomic, copy)NSString *name;
@property(nonatomic, assign)CGFloat price;
- (id)initWithName:(NSString *)name
price:(CGFloat)price;
+ (Book *)bookWithName:(NSString *)name
price:(CGFloat)price;
NSArray *arr = [[NSArray alloc] init];
NSArray *arr1 = [NSArray arrayWithArray:0];
NSArray *arr2 = @[@"1", @"2", @"3", @"4", @"5"];
NSLog(@"%ld", arr2.count);
NSLog(@"%@", [arr2 objectAtIndex:2]);
NSLog(@"%@", arr2);
for (NSInteger i = 0; i < arr2.count; i++) {
NSLog(@"%@", arr2[i]);
}
NSLog(@"%d", [arr2 containsObject:@"6"]);
Student *stu1 = [[Student alloc] initWithName:@"商帅"];
Student *stu2 = [[Student alloc] initWithName:@"刘山山"];
Student *stu3 = [[Student alloc] initWithName:@"杨林"];
Student *stu4 = [[Student alloc] initWithName:@"腾飞"];
Student *stu5 = [[Student alloc] initWithName:@"谭泉元"];
NSArray *stu = @[stu1.name, stu2.name, stu3.name, stu4.name, stu5.name];
for (NSInteger i = 0; i < stu.count; i++) {
NSLog(@"%@", stu[i]);
}
NSLog(@"*********");
NSArray *arr3 = @[@"薛楠",@"杨林",@"刘山山",@"商帅"];
for (NSString *str in arr3) {
NSLog(@"%@", str);
}
NSLog(@"*********");
NSArray *arr4 = @[@"周圣民", @"腾飞", @"刘鑫奇", @"大表姐"];
NSArray *arr0 = @[arr3, arr4];
for (NSArray *temp in arr0) {
for (NSString *str0 in temp) {
NSLog(@"%@", str0);
}
}
NSArray *arr5 = @[stu1, stu2, stu3];
NSArray *arr6 = @[stu4, stu5];
NSArray *arr7 = @[arr5, arr6];
NSLog(@"*********");
for (Student *str1 in arr5) {
NSLog(@"%@", str1.name);
}
NSLog(@"*********");
for (NSArray *str2 in arr7) {
for (Student *str3 in str2) {
NSLog(@"%@", str3.name);
}
}
NSArray *testArr = @[@"1", @"2", @"3", @"4", @"5"];
NSArray *array = [[NSArray alloc] initWithArray:testArr];
NSArray *array1 = [[NSArray alloc] initWithObjects:testArr, nil];
NSLog(@"%@\n%ld", array, array.count);
NSLog(@"%@\n%ld", array1, array1.count);
NSArray *array2 = [NSArray arrayWithArray:testArr];
NSArray *array3 = [NSArray arrayWithObjects:testArr, nil];
NSMutableArray *arr = [[NSMutableArray alloc] init];
NSMutableArray *arr1 = [NSMutableArray array];
NSMutableArray *arr2 = [[NSMutableArray alloc] initWithObjects:@"1",@"2",@"3",@"4", nil];
[arr2 addObject:@"ddada"];
NSLog(@"%@", arr2);
[arr2 removeObjectAtIndex:2];
NSLog(@"%@", arr2);
[arr2 insertObject:@"adada" atIndex:2];
NSLog(@"%@", arr2);
[arr2 replaceObjectAtIndex:2 withObject:@"3"];
NSLog(@"%@", arr2);
[arr2 exchangeObjectAtIndex:0 withObjectAtIndex:4];
NSLog(@"%@", arr2);
[arr2 removeAllObjects];
NSLog(@"%@", arr2);
Book *book1 = [Book bookWithName:@"三国志" price:19.98];
Book *book2 = [Book bookWithName:@"资治通鉴" price:76.50];
Book *book3 = [Book bookWithName:@"洗冤录" price:38.80];
NSMutableArray *bookArr = [NSMutableArray arrayWithObjects:book1, book2, book3, nil];
Book *book4 = [Book bookWithName:@"飞鸟集" price:76];
[bookArr addObject:book4];
for (Book *temp in bookArr) {
NSLog(@"书名:%@,价格:%g", temp.name, temp.price);
}
NSLog(@"************");
[bookArr removeObject:book3];
for (Book *temp in bookArr) {
NSLog(@"书名:%@,价格:%g", temp.name, temp.price);
}
NSLog(@"************");
for (Book *temp in bookArr) {
if ([temp.name isEqualToString:@"飞鸟集"]) {
temp.price = 100;
}
NSLog(@"书名:%@,价格:%g", temp.name, temp.price);
}
NSLog(@"************");
NSMutableArray *bookArr0 = [NSMutableArray array];
for (Book *temp in bookArr) {
if (temp.price >= 70 && temp.price <= 100) {
[bookArr0 addObject:temp];
}
}
for (Book *temp in bookArr0) {
NSLog(@"%@ %g", temp.name, temp.price);
}
for (Book *temp in bookArr) {
if (temp.price == 100) {
temp.name = @"论语";
NSLog(@"%@", temp.name);
}
}
NSArray *testArr = @[@"1", @"2", @"3", @"4", @"5"];
NSMutableArray *muArr = [NSMutableArray arrayWithArray:testArr];