当前位置:网站首页>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
边栏推荐
- 2020美亚团队赛复盘
- PWA 踩坑 - 第一次加载页面后无法获取CacheStorage某些资源
- 数据库概论之MySQL表的增删改查2
- See the picture to understand | How to choose sales indicators to measure the health of business growth
- PMP新考纲通关秘籍,告别抓瞎
- 实验7 MPLS实验
- Redis 常用命令和基本数据结构(数据类型)
- 从云计算到函数计算
- [Dataset][VOC] Eyewear dataset 6000 in VOC format
- 2022.07.31(LC_6133_分组的最大数量)
猜你喜欢

自然语言处理 文本预处理(上)(分词、词性标注、命名实体识别等)
![(Notes are not completed) [Graph Theory] Traversal of graphs](/img/1d/d2909dcfa0ab5c207005971a7b4a2d.gif)
(Notes are not completed) [Graph Theory] Traversal of graphs

【云原生】如何快速部署Kubernetes

59:第五章:开发admin管理服务:12:MongoDB的使用场景;(非核心数据,数据量比较大的非核心数据,人脸照片等隐私的小文件;)

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

OC-错误提示

企业实训复现指导手册——基于华为ModelArts平台的OpenPose模型的训练和推理、基于关键点数据实现对攀爬和翻越护栏两种行为的识别、并完成在图片中只标注发生行为的人

埋点开发流程

PMP新考纲通关秘籍,告别抓瞎

Wuhan 2022 organizing of the high-performance computing added new ecological development of high-performance computing
随机推荐
队列题目:无法吃午餐的学生数量
yml字符串读取时转成数字了怎么解决
Day 4 of HCIP
跨阻放大器
【请教】SQL语句按列1去重来计算列2之和
深度学习网络模型的改进与调整
PMP新考纲通关秘籍,告别抓瞎
FaceBook社媒营销高效转化技巧分享
使用hutool做本地缓存的工具类
Unity Shader学习(七)纹理图像的简单使用
【云原生】如何快速部署Kubernetes
【机器学习】实验6布置:基于集成学习的Amazon用户评论质量预测
Neo4j 中文开发者月刊 - 202207期
你认同这个观点吗?大多数企业的数字化都只是为了缓解焦虑
Connection reset by peer problem analysis
mysql 注入
数据库概论-MySQL的数据表的基本操作
新产品立大功 伟世通第二季度营收双增
吃透Chisel语言.30.Chisel进阶之通信状态机(二)——FSMD:以Popcount为例
OC-NSDictionary