我在objc中定义了以下枚举:
typedef NS_OPTIONS(NSInteger, RKRequestMethod) {
RKRequestMethodGET = 1 << 0,
RKRequestMethodPOST = 1 << 1,
// ...
};
所以在objc中我可以通过将整数值与@( )
:
NSDictionary *dict = @{ @"s": @(RKRequestMethodGET) }
现在很快,我想将这样的枚举存储在字典中:
var v = [String: AnyObject]()
v = ["s": RKRequestMethod.POST
v = ["s": NSNumber(char: RKRequestMethod.POST)]
v = ["s": NSNumber(unsignedChar: RKRequestMethod.POST)]
v = ["s": NSNumber(short: RKRequestMethod.POST)]
v = ["s": NSNumber(unsignedShort: RKRequestMethod.POST)]
// There are approx 10 more of these and I tried them all
答案 0 :(得分:1)
我确实搞清楚了。它实际上很简单:
v = ["s": RKRequestMethod.Any.rawValue]