当前位置:网站首页>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
边栏推荐
- 【机器学习】实验6布置:基于集成学习的Amazon用户评论质量预测
- 59:第五章:开发admin管理服务:12:MongoDB的使用场景;(非核心数据,数据量比较大的非核心数据,人脸照片等隐私的小文件;)
- 张驰咨询:企业实施精益管理的最大障碍,只把精益作为一种工具和方法
- SQL server 2014 怎么一次性导出多个查询结果?
- 以训辅教,以战促学 | 新版攻防世界平台正式上线运营!
- 【CNN回归预测】基于matlab卷积神经网络CNN数据回归预测【含Matlab源码 2003期】
- 倍福使用AdsRemote组件实现和C#的ADS通讯
- 吃透Chisel语言.30.Chisel进阶之通信状态机(二)——FSMD:以Popcount为例
- hdu1752 copy
- 21 days learning challenge 】 【 sequential search
猜你喜欢
随机推荐
_2_顺序表
【ROS基础】rosbag 的使用方法
【机器学习】实验1布置:基于决策树的英雄联盟游戏胜负预测
结构体大小计算--结构体内存对齐
数据库概论之MySQL表的增删改查2
awk语法-01-基础语法(命令、选项、内部变量)
OC-NSSet(集合)
分离轴定理SAT凸多边形精确碰撞检测
逆变器绝缘检测检测功能及软件实现
自然语言处理 文本预处理(上)(分词、词性标注、命名实体识别等)
实例032:反向输出II
入门opencv,欢笑快乐每一天
Connection reset by peer problem analysis
Splunk Filed Alias 字段改名
Unity Shader学习(七)纹理图像的简单使用
mysql 注入
使用hutool做本地缓存的工具类
“蔚来杯“2022牛客暑期多校训练营4,签到题NDKHL
张驰课堂:六西格玛培训工具——箱线图
堡垒机、堡垒机的原理









