当前位置:网站首页>OC-NSNumber and NSValue are generally used for boxing and unboxing
OC-NSNumber and NSValue are generally used for boxing and unboxing
2022-08-02 07:48:00 【Classmate Peng, she is at the same table】
NSNumber
装箱:将值类型转换成引用类型
拆箱:将引用类型转换成值类型
int a = 1; This is the value type It should be some default type
string a;或者NSNumberThis is the reference type Should be able to say yesNSObject
装箱
NSNumber *num1 = [[NSNumber alloc]initWithInt:20];
NSLog(@"%@ %@",num1,[num1 class]);//20 __NSCFNumber
NSNumber *num2 = [[NSNumber alloc]initWithChar:'a'];
NSLog(@"%@",num2);//97 This is to convert the letters into ascll码
NSNumber *num3 = @300;
NSLog(@"%@",num3);//300
int a = 29;
NSNumber *num5 = @(a);
NSLog(@"%@",num5);//5
拆箱
通过intValue floatValue拆箱
NSNumber *num3 = @300;
NSLog(@“%d”,num3 intValue);//300
NSNumber *num3 = @300.0;
NSLog(@“%f”,num3 floatValue);//300.0
NSValue(I don't understand)
typedef struct
{
int age;
char* name;
chat sex;
} SPerson
Sperson p;
p.name = "Yang";
p.age = 10;
p.sex = 'w';
//Convert a struct toNSValue对象
NSValue* value = [NSValue valueWithBytes:&p objCType:@encode(SPerson)];
SPerson p2;
//将一个NSValueObjects are converted to structs
[value getValue:&p2];
NSLog(@"%s",p2.name);
NSLog(@"%d",p2.age);
NSLog(@"%c",p2.sex);
NSRange range = {
12,2};
//Commonly used structure packing
NSValue *rvalue = [NSValue valueWithRange:range];
//rangeValue将NSRange拆箱
NSLog(@"%@",NSStringFromRange([rvalue rangeValue]));
边栏推荐
- 电商库存系统的防超卖和高并发扣减方案
- (2022牛客多校五)D-Birds in the tree(树形DP)
- 2022.07.31(LC_6133_分组的最大数量)
- optional
- Wuhan 2022 organizing of the high-performance computing added new ecological development of high-performance computing
- php删除一维数组中一个值
- 图腾柱和推挽电路介绍
- OC-错误提示
- 实验7 MPLS实验
- 解决:- SPY: No data found for this date range, symbol may be delisted报错
猜你喜欢
随机推荐
Revitalize rural circular economy and digital chain to link agricultural "ecological chain"
OC-错误提示
堡垒机、堡垒机的原理
[21天学习挑战赛——内核笔记](一)——设备树的概述(硬件、目标、效果、文件类型)
【暑期每日一题】洛谷 P1192 台阶问题
Gradle系列——Gradle插件(基于Gradle文档7.5)day3-2
2022.07.31(LC_6132_使数组中所有元素都等于零)
速看!PMP新考纲、PMBOK第七版解读
(2022牛客多校五)B-Watches(二分)
论文阅读 (64):Weakly-supervised Video Anomaly Detection with Robust Temporal Feature Magnitude Learning
【图像隐藏】基于matlab混合DWT-HD-SVD数字图像水印方法技术【含Matlab源码 2007期】
【论文精读】Geometric Structure Preserving Warp for Natural Image Stitching
从云计算到函数计算
【请教】SQL语句按列1去重来计算列2之和
封装class类一次性解决全屏问题
埋点开发流程
PMP新考纲考试内容介绍
OC-NSArray
笔记本开机黑屏提示:ERROR 0199:System Security-Security password retry count exceeded
2022夏暑假每日一题(六)









