菜鸟:IOS 学习:烧烤记(第三天)
13、- (void)setArray:(NSArray *)otherArray;指定数组B替换A
NSMutableArray * demoMutableArray = [NSMutableArray arrayWithObjects:@"January", @"February", @"March", nil];
NSArray *demoArray = [NSArray arrayWithObjects:@"April", @"May", nil];
[demoMutableArray setArray:demoArray];
NSLog(@"%@", demoMutableArray);
2013-03-14 08:27:02.297 NSStringDemo[639:303] (
April,
May
)
14、- (void)sortUsingFunction:(NSInteger (*)(id, id, void *))compare context:(void *)context; 指定方法升序比较
15、- (void)sortUsingSelector:(SEL)comparator;指定方法升序比较
16、- (void)insertObjects:(NSArray *)objects atIndexes:(NSIndexSet *)indexes; 指定索引集合插入数组元素
[demoMutableArray insertObjects:demoArray atIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(3, 2)]];
NSLog(@"%@", demoMutableArray);
2013-03-14 08:37:44.107 NSStringDemo[763:303] (
January,
February,
March,
April,
May
)
17、- (void)removeObjectsAtIndexes:(NSIndexSet *)indexes; 移除指定索引集合元素
[demoMutableArray removeObjectsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 3)]];
NSLog(@"%@", demoMutableArray);
2013-03-14 08:39:25.053 NSStringDemo[812:303] (
April,
May
)
18、- (void)replaceObjectsAtIndexes:(NSIndexSet *)indexes withObjects:(NSArray *)objects; 替换指定索引集合的数组元素
[demoMutableArray replaceObjectsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, 2)] withObjects:demoArray];
NSLog(@"%@", demoMutableArray);
2013-03-14 08:44:29.244 NSStringDemo[1071:303] (
January,
April,
May
)
19、- (void)setObject:(id)obj atIndexedSubscript:(NSUInteger)idx NS_AVAILABLE(10_8, 6_0); 指定索引替换新的数组元素
[demoMutableArray setObject:demoArray atIndexedSubscript:3];
NSLog(@"%@", demoMutableArray);
2013-03-14 08:46:45.696 NSStringDemo[1161:303] (
January,
April,
May,
(
April,
May
)
)
20、- (void)sortUsingComparator:(NSComparator)cmptr NS_AVAILABLE(10_6, 4_0); 指定块方法排序数组元素
NSMutableArray * demoThreeArray = [[[NSMutableArray alloc] initWithObjects:@"23", @"3", @"13", nil] autorelease];
[demoThreeArray sortUsingComparator: ^(id objOne, id objTwo) {
NSInteger intOne = [objOne integerValue];
NSInteger intTwo = [objTwo integerValue];
if (intOne> intTwo) {
return (NSComparisonResult)NSOrderedDescending;
}
if (intOne < intTwo) {
return (NSComparisonResult)NSOrderedAscending;
}
return (NSComparisonResult)NSOrderedSame;
}];
NSLog(@"%@", demoThreeArray);
2013-03-14 09:01:55.568 NSStringDemo[1493:303] (
3,
13,
23
)
21、- (void)sortWithOptions:(NSSortOptions)opts usingComparator:(NSComparator)cmptr NS_AVAILABLE(10_6, 4_0);指定块比较数组
[demoThreeArray sortWithOptions:NSSortConcurrent usingComparator:^NSComparisonResult(id objOne, id objTwo) {
NSInteger intOne = [objOne integerValue];
NSInteger intTwo = [objTwo integerValue];
if (intOne> intTwo) {
return (NSComparisonResult)NSOrderedAscending;
}
if (intOne < intTwo) {
return (NSComparisonResult)NSOrderedDescending;
}
return (NSComparisonResult)NSOrderedSame;
}];
NSLog(@"%@", demoThreeArray);
2013-03-14 09:05:50.176 NSStringDemo[1583:303] (
23,
13,
3
)
22、+ (id)arrayWithCapacity:(NSUInteger)numItems; 初始化化数组对象容量
23、- (id)initWithCapacity:(NSUInteger)numItems;初始化化数组对象容量
NSMutableArray *demoOneCapacity = [NSMutableArray arrayWithCapacity:3];
[demoOneCapacity addObject:@"demoOne"];
NSMutableArray *demoTwoCapacity = [[[NSMutableArray alloc] initWithCapacity:3] autorelease];
[demoTwoCapacity addObject:@"demoTwo"];
NSLog(@"%@ --- %@", demoOneCapacity, demoTwoCapacity);
2013-03-14 09:11:59.373 NSStringDemo[1743:303] (
demoOne
) --- (
demoTwo
)
浙公网安备 33010602011771号