博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
NSNumber(把数字存进数组字典等的问题)
阅读量:6542 次
发布时间:2019-06-24

本文共 3569 字,大约阅读时间需要 11 分钟。

官方文档地址https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/Reference/Reference.html

 

 

NSUInteger是无符号的整型, NSInteger是有符号的整型,在表视图应用中常见 NSUInteger row= [indexPath row];因为这是显示tableViewCell有多少个,只能是非零整数的,也就是说,NSUInteger常用于索引值; int与 NSInteger没有本质区别,只是一个定义为题

字符不能作为对象被存在数组字典中要转化为对象(NSNumber)类型

NSNumber的属性与方法

@interface NSNumber : NSValue

 

- (instancetype)initWithCoder:(NSCoder *)aDecoder NS_DESIGNATED_INITIALIZER;

- (NSNumber *)initWithChar:(char)value NS_DESIGNATED_INITIALIZER;

- (NSNumber *)initWithUnsignedChar:(unsigned char)value NS_DESIGNATED_INITIALIZER;

- (NSNumber *)initWithShort:(short)value NS_DESIGNATED_INITIALIZER;

- (NSNumber *)initWithUnsignedShort:(unsigned short)value NS_DESIGNATED_INITIALIZER;

- (NSNumber *)initWithInt:(int)value NS_DESIGNATED_INITIALIZER;

- (NSNumber *)initWithUnsignedInt:(unsigned int)value NS_DESIGNATED_INITIALIZER;

- (NSNumber *)initWithLong:(long)value NS_DESIGNATED_INITIALIZER;

- (NSNumber *)initWithUnsignedLong:(unsigned long)value NS_DESIGNATED_INITIALIZER;

- (NSNumber *)initWithLongLong:(long long)value NS_DESIGNATED_INITIALIZER;

- (NSNumber *)initWithUnsignedLongLong:(unsigned long long)value NS_DESIGNATED_INITIALIZER;

- (NSNumber *)initWithFloat:(float)value NS_DESIGNATED_INITIALIZER;

- (NSNumber *)initWithDouble:(double)value NS_DESIGNATED_INITIALIZER;

- (NSNumber *)initWithBool:(BOOL)value NS_DESIGNATED_INITIALIZER;

- (NSNumber *)initWithInteger:(NSInteger)value NS_AVAILABLE(10_5, 2_0) NS_DESIGNATED_INITIALIZER;

- (NSNumber *)initWithUnsignedInteger:(NSUInteger)value NS_AVAILABLE(10_5, 2_0) NS_DESIGNATED_INITIALIZER;

 

@property (readonly) char charValue;

@property (readonly) unsigned char unsignedCharValue;

@property (readonly) short shortValue;

@property (readonly) unsigned short unsignedShortValue;

@property (readonly) int intValue;

@property (readonly) unsigned int unsignedIntValue;

@property (readonly) long longValue;

@property (readonly) unsigned long unsignedLongValue;

@property (readonly) long long longLongValue;

@property (readonly) unsigned long long unsignedLongLongValue;

@property (readonly) float floatValue;

@property (readonly) double doubleValue;

@property (readonly) BOOL boolValue;

@property (readonly) NSInteger integerValue NS_AVAILABLE(10_5, 2_0);

@property (readonly) NSUInteger unsignedIntegerValue NS_AVAILABLE(10_5, 2_0);

 

@property (readonly, copy) NSString *stringValue;

 

- (NSComparisonResult)compare:(NSNumber *)otherNumber;

 

- (BOOL)isEqualToNumber:(NSNumber *)number;

 

- (NSString *)descriptionWithLocale:(id)locale;

 

@end

 

@interface NSNumber (NSNumberCreation)

 

+ (NSNumber *)numberWithChar:(char)value;

+ (NSNumber *)numberWithUnsignedChar:(unsigned char)value;

+ (NSNumber *)numberWithShort:(short)value;

+ (NSNumber *)numberWithUnsignedShort:(unsigned short)value;

+ (NSNumber *)numberWithInt:(int)value;

+ (NSNumber *)numberWithUnsignedInt:(unsigned int)value;

+ (NSNumber *)numberWithLong:(long)value;

+ (NSNumber *)numberWithUnsignedLong:(unsigned long)value;

+ (NSNumber *)numberWithLongLong:(long long)value;

+ (NSNumber *)numberWithUnsignedLongLong:(unsigned long long)value;

+ (NSNumber *)numberWithFloat:(float)value;

+ (NSNumber *)numberWithDouble:(double)value;

+ (NSNumber *)numberWithBool:(BOOL)value;

+ (NSNumber *)numberWithInteger:(NSInteger)value NS_AVAILABLE(10_5, 2_0);

+ (NSNumber *)numberWithUnsignedInteger:(NSUInteger)value NS_AVAILABLE(10_5, 2_0);

 

例如

 

[[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithFloat:123.4545] forKey:@"fds"];

 

 

 

 

转载于:https://www.cnblogs.com/dlwj/p/4894014.html

你可能感兴趣的文章
编译tomcat
查看>>
oracle-xe手工创建数据库
查看>>
UG中卸载被占用的DLL
查看>>
eclipse 设置注释模板详解,与导入模板方法介绍总结
查看>>
Cocos2d-x3.2 文字显示
查看>>
ipsec的***在企业网中的经典应用
查看>>
过来人谈《去360还是留在百度?》
查看>>
特此说明
查看>>
poj3262
查看>>
linux C 9*9
查看>>
python的string操作总结
查看>>
如何把word中的图片怎么导出来呢?
查看>>
c++ Constructor FAQ 继续
查看>>
ubuntu samba服务器多用户配置【转】
查看>>
母线的种类与作用是什么(转)
查看>>
【Xamarin 挖墙脚系列:IOS 开发界面的3种方式】
查看>>
Atitit.工作流系统的本质是dsl 图形化的dsl 4gl
查看>>
4-5-创建索引表-串-第4章-《数据结构》课本源码-严蔚敏吴伟民版
查看>>
go run main.go undefined? golang main包那点事
查看>>
从零开始写一个npm包,一键生成react组件(偷懒==提高效率)
查看>>