Shi*_*zam 2 set bitmask swift swift2
直到Swift 1.2你可以~在位掩码上执行(NOT):
bitmask = ~otherBitmask
但是在Swift 2.0中,bitmasks现在已经OptionSetType无法使用a ~了OptionSetType,你现在如何对a进行~操作OptionSetType?
您可以对原始值执行"按位NOT".例:
let otherBitmask : NSCalendarOptions = [.MatchLast, .MatchNextTime]
let bitmask = NSCalendarOptions(rawValue: ~otherBitmask.rawValue)
如果您经常需要,可以为以下内容定义通用
 ~运算符OptionSetType:
prefix func ~<T : OptionSetType where T.RawValue : BitwiseOperationsType>(rhs: T) -> T {
    return T(rawValue: ~rhs.rawValue)
}
let otherBitmask : NSCalendarOptions = [.MatchLast, .MatchNextTime]
let bitmask = ~otherBitmask
| 归档时间: | 
 | 
| 查看次数: | 285 次 | 
| 最近记录: |