Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/99.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在字典中传递常数_Ios_Objective C_Nsdictionary_Nsvalue - Fatal编程技术网

Ios 如何在字典中传递常数

Ios 如何在字典中传递常数,ios,objective-c,nsdictionary,nsvalue,Ios,Objective C,Nsdictionary,Nsvalue,我想知道是否有办法将UITableViewStylePlain这样的常量传递到NSDictionary中 我使用NSValue传递值类型,如下所示: CGRect myRec = CGRectMake(0,0,320,568); NSDictionary *myDic = @{@"val":[NSValue valueWithCGRect:myRec]}; CGRect yourRec = [[myDic valueForKey:@"val"] CGRectValue]; 我的问题是,对于像U

我想知道是否有办法将UITableViewStylePlain这样的常量传递到NSDictionary中

我使用NSValue传递值类型,如下所示:

CGRect myRec = CGRectMake(0,0,320,568);
NSDictionary *myDic = @{@"val":[NSValue valueWithCGRect:myRec]};
CGRect yourRec = [[myDic valueForKey:@"val"] CGRectValue];
我的问题是,对于像UITableViewStylePlain这样的常量,我如何做到这一点?大概是这样的:

NSDictionary *myDic = @{@"style":[NSValue value:UITableViewStylePlain withObjCType:enum]};

我意识到enum不是Objective类型…:(

枚举值是数字,因此您可以使用
NSNumber
将它们存储在字典中:

NSDictionary *myDic = @{@"style":@[NSNumber numberWithInt:UITableViewStylePlain]};

enum
通常保存
NSInteger
(有时
NSInteger
),因此在这种情况下
NSNumber
也足够好,例如:

NSDictionary * myDic = @{ @"style" : @(UITableViewStylePlain) };