当前位置:网站首页>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
边栏推荐
- C#重点问题之Struct和Class的异同
- Vscode connect to remote server "Acquiring the lock on the/home / ~ 'problem
- System.Security.SecurityException: 未找到源,但未能搜索某些或全部事件日志。不可 访问的日志: Security
- 笔记本开机黑屏提示:ERROR 0199:System Security-Security password retry count exceeded
- The second day HCIP
- WebGPU 导入[2] - 核心概念与重要机制解读
- 实例030:回文数
- Neo4j 中文开发者月刊 - 202207期
- 反射课后习题及做题记录
- Analysis of GCC compiler technology
猜你喜欢

Neo4j 中文开发者月刊 - 202207期

【故障诊断分析】基于matlab FFT轴承故障诊断(包络谱)【含Matlab源码 2002期】

System.Security.SecurityException: 未找到源,但未能搜索某些或全部事件日志。不可 访问的日志: Security
![WebGPU 导入[2] - 核心概念与重要机制解读](/img/8f/195a3b04912d8872d025df58ab5960.png)
WebGPU 导入[2] - 核心概念与重要机制解读

Gradle系列——Gradle插件(基于Gradle文档7.5)day3-2

深度学习网络模型的改进与调整

自然语言处理 文本预处理(上)(分词、词性标注、命名实体识别等)

(2022牛客多校五)B-Watches(二分)

2022夏暑假每日一题(六)

Unity Shader学习(七)纹理图像的简单使用
随机推荐
OC-范畴
FaceBook社媒营销高效转化技巧分享
实例030:回文数
【机器学习】实验1布置:基于决策树的英雄联盟游戏胜负预测
逆变器绝缘检测检测功能及软件实现
JS初识高阶函数和函数柯里化
深度学习网络模型的改进与调整
OC-NSSet(集合)
OC-NSArray
【机器学习】实验5布置:AAAI会议论文聚类分析
从云计算到函数计算
apt & apt-get命令
数据库概论-MySQL的数据表的基本操作
论文《Deep Multifaceted Transformers for Multi-objective Ranking in Large-Scale E-commerce Recommender》
【网络】IP、子网掩码
Go 实现分布式锁
Neo4j 中文开发者月刊 - 202207期
交换网络----三种生成树协议
Analysis of GCC compiler technology
查看端口号占用