最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
IOS 开发之ObjectiveC的变量类型的字符代表
时间:2022-06-26 05:59:50 编辑:袖梨 来源:一聚教程网
IOS 开发之ObjectiveC的变量类型的字符代表
实例代码:
NSDictionary *dic = @{@"1":[NSNumber numberWithBool:YES], @"2":[NSNumber numberWithChar:'1'], @"3":[NSNumber numberWithDouble:2.0], @"4":[NSNumber numberWithFloat:2.0f], @"5":[NSNumber numberWithInt:1], @"6":[NSNumber numberWithInteger:2], @"7":[NSNumber numberWithLong:30], @"8":[NSNumber numberWithLongLong:3], @"9":[NSNumber numberWithShort:4], @"10":[NSNumber numberWithUnsignedChar:'1'], @"11":[NSNumber numberWithUnsignedInt:3], @"12":[NSNumber numberWithUnsignedInteger:35], @"13":[NSNumber numberWithUnsignedLong:45], @"14":[NSNumber numberWithUnsignedLongLong:59], @"15":[NSNumber numberWithUnsignedShort:4] }; for(NSString *key in dic){ id value = [dic valueForKey:key]; if([value isKindOfClass:[NSNumberclass]]){ constcharchar * pObjCType = [((NSNumber*)value) objCType]; NSLog(@"%@,%s",key,pObjCType); } }
以上的输出结果证明:
UnsignedChar =>s Char =>c UnsignedShort =>i LongLong =>d UnsignedInt =>q Float =>f Int =>i UnsignedInteger =>q Integer =>q UnsignedLong =>q Long =>q LongLong =>q UnsignedLongLong=>q Bool =>c Short =>s double =>d
再看以下代码,用@encode关键字的
NSLog(@"1=>%s",@encode(BOOL)); NSLog(@"2=>%s",@encode(char)); NSLog(@"3=>%s",@encode(double)); NSLog(@"4=>%s",@encode(float)); NSLog(@"5=>%s",@encode(int)); NSLog(@"6=>%s",@encode(NSInteger)); NSLog(@"7=>%s",@encode(long)); NSLog(@"8=>%s",@encode(longlong)); NSLog(@"9=>%s",@encode(short)); NSLog(@"10=>%s",@encode(unsignedchar)); NSLog(@"11=>%s",@encode(unsignedint)); NSLog(@"12=>%s",@encode(unsignedlong));//unsigned NSInteger NSLog(@"13=>%s",@encode(unsignedlong)); NSLog(@"14=>%s",@encode(unsignedlonglong)); NSLog(@"15=>%s",@encode(unsignedshort));
以上的输出结果证明:
BOOL=>c char=>c double=>d float=>f int=>i NSInteger=>q long=>q longlong=>q short=>s unsignedchar=>C unsignedint=>I unsigned NSInteger=>Q unsignedlong=>Q unsignedlonglong=>Q unsignedshort=>S
读者可以根据这种方式来判断某个变量到底属于哪种类型。
相关文章
- 《彩色点点战争》推图常用三大主c玩法详解 01-23
- 《燕云十六声》池鱼林木任务攻略 01-23
- 《大连地铁e出行》查看行程记录方法 01-23
- 《明日方舟》2025春节限定干员余角色介绍 01-23
- 《崩坏:星穹铁道》万敌光锥搭配攻略 01-23
- 《燕云十六声》一药千金任务攻略 01-23