首页 > 其他分享 >OC之【NSNumber的使用】

OC之【NSNumber的使用】

时间:2022-12-09 15:03:58浏览次数:36  
标签:int number1 OC number num NSNumber 使用 array

#import <Foundation/Foundation.h>

void
// 将int类型的10 包装成 一个NSNumber对象
NSNumber *number = [NSNumbernumberWithInt:10];
NSLog(@"number=%@", number);

NSMutableArray *array = [NSMutableArrayarray];
//添加数值到数组中
addObject:number];

//取出来还是一个NSNumber对象,不支持自动解包(也就是不会自动转化为int类型)
NSNumber *number1 = [array lastObject];
// 将NSNumber转化成int类型
int num = [number1 intValue];
NSLog(@"num=%i", num);
}

int main(int argc,const char
{
@autoreleasepool {
number();
}
return 0;
}

标签:int,number1,OC,number,num,NSNumber,使用,array
From: https://blog.51cto.com/u_15907570/5925313

相关文章

  • OC之【NSDictionary详解】
    main.m文件#import<Foundation/Foundation.h>#import"Student.h"字典的初始化void//NSDictionary是不可变的NSDictionary*dict=[NSDictionarydictionaryWit......
  • OC之【c语言结构体】
    <stdio.h>void//这个机构只能在函数内部使用//定义一个名为Student的结构体类型structintage;//年龄char*name;//姓名floatheight;//身高};......
  • OC之【NSMutableDictionary的使用】
    main.m文件#import<Foundation/Foundation.h>#import"Student.h"可变字典的使用void//创建一个空的字典NSMutableDictionary*dict=[NSMutableDictionarydicti......
  • OC之【NSValue的使用】
    #import<Foundation/Foundation.h>voidCGPointpoint=CGPointMake(10,10);//将结构体变量包装成一个对象NSValue*value=[NSValuevalueWithPoint:point];......
  • OC之【enum枚举】
    void//定义一种枚举类型enum//定义一个枚举变量senumSeasons=winter;}void//定义枚举类型的同时定义一个枚举变量senumSeason{spring,summer,......
  • OC之【NSDate使用】
    #import<Foundation/Foundation.h>日期创建void//date方法返回的就是当前时间(now)NSDate*date=[NSDatedate];//now:21:09:40//date:21:09:50......
  • OC之【内存管理】
    Student@synthesizeage=_age;//在xcode4.5以上环境下可以省略-(void)dealloc{@"%@被销毁了",self);super//一定要调用super的dealloc方法,而且最好放在最......
  • OC之【NSObject使用】
    main.m文件#import<Foundation/Foundation.h>#import"Student.h"#import"Person.h"常用方法voidStudent*stu=[[[Studentalloc]init]autorelease];//isKin......
  • OC之【@property的用法】
    1.这里的retain代表:在set方法中,release旧值,retain新值(nonatomic,retain)Book*book;(retain)Card*card;代表只生成get方法的声明默认是readwrite,同时生成get和set......
  • OC之【objective-c中结构体】
    #import<Foundation/Foundation.h>void//定义了Date这种结构体类型structintintint};//定义结构体变量structDated={2013,4,5};day=6;}voi......