当前位置:网站首页>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
边栏推荐
- Submit code process
- ADS通信--倍福PLC和C#TextBox控件实现数据绑定的方法
- Vscode connect to remote server "Acquiring the lock on the/home / ~ 'problem
- 【故障诊断分析】基于matlab FFT轴承故障诊断(包络谱)【含Matlab源码 2002期】
- 电商库存系统的防超卖和高并发扣减方案
- [Dataset][VOC] Male and female dataset voc format 6188 sheets
- 【ROS基础】rosbag 的使用方法
- Splunk Field Caculated 计算字段
- 数据库概论之MySQL表的增删改查2
- LeetCode Algorithm 1374. 生成每种字符都是奇数个的字符串
猜你喜欢
【心电信号】基于matlab心率检测【含Matlab源码 1993期】
“蔚来杯“2022牛客暑期多校训练营4,签到题NDKHL
WebGPU 导入[2] - 核心概念与重要机制解读
吃透Chisel语言.30.Chisel进阶之通信状态机(二)——FSMD:以Popcount为例
正则表达式的理解学习
聊天机器人如何提升独立站的营销水平?
【图像隐藏】基于matlab混合DWT-HD-SVD数字图像水印方法技术【含Matlab源码 2007期】
论文《Deep Multifaceted Transformers for Multi-objective Ranking in Large-Scale E-commerce Recommender》
Vscode connect to remote server "Acquiring the lock on the/home / ~ 'problem
张驰课堂:六西格玛测量系统的误差分析与判定
随机推荐
问个问题,我的Flinkcdc已经跑通了,可以监听msql的binlog了,也能发送kafk
Wuhan 2022 organizing of the high-performance computing added new ecological development of high-performance computing
以训辅教,以战促学 | 新版攻防世界平台正式上线运营!
根据一个字段的内容去更新另一个字段的数据,这样的sql语句该怎么样书写
Splunk Field Caculated 计算字段
堡垒机、堡垒机的原理
速看!PMP新考纲、PMBOK第七版解读
MPLS的相关技术
实例030:回文数
LeetCode SQL 197. 上升的温度
jvm 二之 栈帧内部结构
【CV】OpenVINO安装教程
Connection reset by peer problem analysis
PMP新考纲考试内容介绍
聊天机器人如何提升独立站的营销水平?
电商库存系统的防超卖和高并发扣减方案
Submit code process
“蔚来杯“2022牛客暑期多校训练营5,签到题KBGHFCD
Facebook社媒营销的5大技巧,迅速提高独立站转化率!
59:第五章:开发admin管理服务:12:MongoDB的使用场景;(非核心数据,数据量比较大的非核心数据,人脸照片等隐私的小文件;)