本文主要是介绍【Foundation-86-3】#import Foundation/NSValue.h 初始化,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
@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;
//64 推荐使用,其他少用
- (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);//64 推荐使用,其他少用
@property (readonly) NSUInteger unsignedIntegerValue NS_AVAILABLE(10_5, 2_0);
@property (readonly, copy) NSString *stringValue;//nsnumber 变成字符串
NSNumber *strNumber = [NSNumber numberWithInteger:3];NSString *str = [strNumber stringValue];NSLog(@"%@",str);
- (NSComparisonResult)compare:(NSNumber *)otherNumber;//比较,排序用
NSNumber *number1 = [NSNumber numberWithInteger:13];NSNumber *number2 = [NSNumber numberWithInteger:14];NSComparisonResult result = [number1 compare:number2];if (result == NSOrderedAscending) {NSLog(@"升序");//number2 比 number1 大}else if (result == NSOrderedSame){NSLog(@"一致");}else if (result == NSOrderedDescending){NSLog(@"降序");}else{NSLog(@"error");}
- (BOOL)isEqualToNumber:(NSNumber *)number;//判断是否一致
NSNumber *number1 = [NSNumber numberWithInteger:13];NSNumber *number2 = [NSNumber numberWithInteger:14];if ([number1 isEqualToNumber:number2]) {NSLog(@"same");}else{NSLog(@"nonono");}
- (NSString *)descriptionWithLocale:(id)locale;//本地化的字符串,规范化。继续研究 NSLocale
NSNumber *number2 = [NSNumber numberWithInteger:1314];NSString *string = [number2 descriptionWithLocale:[NSLocale currentLocale]];NSLog(@"%@",string);
@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);
@end
这篇关于【Foundation-86-3】#import Foundation/NSValue.h 初始化的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!