繁体   English   中英

将NS_OPTIONS存储在Swift字典中

[英]Store NS_OPTIONS in swift dictionary

我在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

我确实知道了。 实际上很简单:

v = ["s": RKRequestMethod.Any.rawValue]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM