当前位置:网站首页>OC-NSArray
OC-NSArray
2022-08-02 07:48:00 【Peng classmate her deskmate】
The array can only store objects, not basic data types
Cannot store nil nil is used to mark the end of the array
Initialization
NSArray *array = [NSMutableArray array];
NSArray *array = [NSArray arrayWithObjects:@"123",@2,@"wf"];
[NSNull null]null object
NSArray *array = [NSArray arrayWithObjects:[NSNull null],[NSNull null],[NSNull null],nil];
NSLog(@"%@",array);//"","",""
Add
[array addObject:@"1"];
[array addObjectsFromArray:@[@"2",@"3"]];]
Insert
[array insertObject:@“0” atIndex:0];
Delete
Delete the specified object
[array removeObject:@“2”];
Delete the last item
[array removeLastObject];
Delete the object under the specified index
[array removeObjectAtIndex:1];
Delete subarray
[array removeObjectsInArray:@[@"0",@"1"]];
Replace the object in the array according to the index
[array replaceObjectAtIndex:1 withObject:@"a"];
Exchange objects under two indices
[array exchangeObjectAtIndex:0 withObjectAtIndex:2];
Override Array
[array setArray:@[@"a",@"b",@"c"]];//Equal to the original array does not exist, and a new array is replaced
Enumeration type
This kind can only choose one
typedef NS-ENUM(NSUInteger,CustomType)
{
ONE,
TWO,
THREE,
};
This can be multiple choices
typedef NS-OPTIONS(NSUInteger,CustomType)
{
ONE =0,
TWO =1<<0,//1
THREE =1<<1,//2 Because of this enumeration, multiple selection will notOverwrite the last selection
};
When multiple selections are made, use | connect such as ONE | TWO
Common methods
Get the first element in the array
array.firstObject
Get the last element of the array
array.lastObject
Get the specified index subscript in the array
array[1]
Determine if the array contains an item
-(BOOL)contatinsObject:(ObjectType)anObject;
If you want to determine your own definition, you need to rewrite the class -(BOOL)isEqual:(id)object
ArrayEnumeration
for(NSString *string in array)
{
NSLog(@“%@”,string);
}
Send a message to each object in the array
[array makeObjectsPerformSelector:@selector(test)];
Return the index value according to the object
[array indexOfObject:@"c"];
Append the object after the immutable array
[array arrayByAddingObject:@""d"];
Sort
sortedArrayUsingSelector
Sort the array of custom objects
[array sortedArrayUsingSelector:@selector(compareAge:)]//This compareAge method needs to be declared and implemented
sortedArrayUsingComparator sorts the array of custom objects by block
Check it out for yourself
边栏推荐
猜你喜欢

入门opencv,欢笑快乐每一天

主流定时任务解决方案全横评

“蔚来杯“2022牛客暑期多校训练营5,签到题KBGHFCD

(2022牛客多校五)C-Bit Transmission(思维)

MQ带来的一些问题、及解决方案
![(Part of it is not understood, and the notes are not completed) [Graph Theory] Difference Constraints](/img/e0/385579fc8657db8b175318bd739908.gif)
(Part of it is not understood, and the notes are not completed) [Graph Theory] Difference Constraints

【请教】SQL语句按列1去重来计算列2之和

HCIP day 3 experiment

第06章 索引的数据结构【2.索引及调优篇】【MySQL高级】

21 days learning challenge 】 【 sequential search
随机推荐
根据一个字段的内容去更新另一个字段的数据,这样的sql语句该怎么样书写
牛客编程题中——需要处理输入较大数的题目
“蔚来杯“2022牛客暑期多校训练营4,签到题NDKHL
第06章 索引的数据结构【2.索引及调优篇】【MySQL高级】
FaceBook社媒营销高效转化技巧分享
Project development specification
OC-范畴
File upload vulnerability (2)
实例030:回文数
逆变器绝缘检测检测功能及软件实现
MQ带来的一些问题、及解决方案
C#重点问题之Struct和Class的异同
hdu1752 copy
队列题目:无法吃午餐的学生数量
【杂】pip换国内源教程及国内源地址
【暑期每日一题】洛谷 P1255 数楼梯
跨阻放大器
实例029:反向输出
Day 4 of HCIP
堡垒机、堡垒机的原理