当前位置:网站首页>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
边栏推荐
- 正则表达式的理解学习
- Splunk Field Caculated 计算字段
- (2022牛客多校五)B-Watches(二分)
- PWA 踩坑 - 第一次加载页面后无法获取CacheStorage某些资源
- See the picture to understand | How to choose sales indicators to measure the health of business growth
- WebGPU 导入[2] - 核心概念与重要机制解读
- 2022年数据泄露平均成本高达435万美元,创历史新高!
- System.Security.SecurityException: 未找到源,但未能搜索某些或全部事件日志。不可 访问的日志: Security
- 倍福使用AdsRemote组件实现和C#的ADS通讯
- 【机器学习】实验6布置:基于集成学习的Amazon用户评论质量预测
猜你喜欢

数据库概论-MySQL的数据表的基本操作

【心电信号】基于matlab心率检测【含Matlab源码 1993期】
![[Dataset][VOC] Male and female dataset voc format 6188 sheets](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[Dataset][VOC] Male and female dataset voc format 6188 sheets

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

论文阅读 (64):Weakly-supervised Video Anomaly Detection with Robust Temporal Feature Magnitude Learning

2020美亚团队赛复盘

责任链模式(Chain Of Responsibility)

【图像去噪】基于matlab双立方插值和稀疏表示图像去噪【含Matlab源码 2009期】

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

交换网络----三种生成树协议
随机推荐
Day 4 of HCIP
mysql 注入
OC-NSDictionary
Facebook社媒营销的5大技巧,迅速提高独立站转化率!
The second day HCIP
反射课后习题及做题记录
倍福使用AdsRemote组件实现和C#的ADS通讯
实例029:反向输出
根据一个字段的内容去更新另一个字段的数据,这样的sql语句该怎么样书写
【杂】pip换国内源教程及国内源地址
数据库概论-MySQL的数据表的基本操作
LeetCode SQL 197. 上升的温度
使用hutool做本地缓存的工具类
自然语言处理 文本预处理(下)(张量表示、文本数据分析、文本特征处理等)
OC-NSNumber和NSValue一般用来装箱拆箱
牛客编程题中——需要处理输入较大数的题目
JS初识高阶函数和函数柯里化
敏捷、DevOps和嵌入式系统测试
暑假第五周总结
ADS通信--倍福PLC和C#TextBox控件实现数据绑定的方法