2

I'm wondering if there is a way to pass a constant like UITableViewStylePlain into NSDictionary.

I am passing value types using NSValue like so:

CGRect myRec = CGRectMake(0,0,320,568);
NSDictionary *myDic = @{@"val":[NSValue valueWithCGRect:myRec]};
CGRect yourRec = [[myDic valueForKey:@"val"] CGRectValue];

My question is how do I do this for a constant like UITableViewStylePlain? Something like this:

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

I realize enum is not an ObjectiveC type... :(

JackyJohnson
  • 3,106
  • 3
  • 28
  • 35

2 Answers2

3

the enum usually holds NSInteger (sometimes NSUInteger), so an NSNumber also can be good enough in that case, like:

NSDictionary * myDic = @{ @"style" : @(UITableViewStylePlain) };
holex
  • 23,961
  • 7
  • 62
  • 76
2

Enum values are numbers so you can use NSNumber to store them in the dictionary :

NSDictionary *myDic = @{@"style":@[NSNumber numberWithInt:UITableViewStylePlain]};
giorashc
  • 13,691
  • 3
  • 35
  • 71