作为标题,为什么按位运算符不能应用于swift中的布尔类型,哪种swift数据类型可以与按位运算符一起使用?
整数就是有位的整数,因此所有整数类型都可以进行按位运算,就像您只是通过查询标头就可以很容易地看出来。例如,按位与:
public func &(lhs: Int, rhs: Int) -> Int
public func &(lhs: UInt, rhs: UInt) -> UInt
public func &(lhs: Int64, rhs: Int64) -> Int64
public func &(lhs: UInt64, rhs: UInt64) -> UInt64
public func &(lhs: Int32, rhs: Int32) -> Int32
public func &(lhs: UInt32, rhs: UInt32) -> UInt32
public func &(lhs: Int16, rhs: Int16) -> Int16
public func &(lhs: UInt16, rhs: UInt16) -> UInt16
public func &(lhs: Int8, rhs: Int8) -> Int8
public func &(lhs: UInt8, rhs: UInt8) -> UInt8
布尔不是Swift中的数字类型;布尔值与逻辑有关,因此它们进行逻辑运算。例如,这是逻辑和:
public func &&<T : BooleanType, U : BooleanType>(lhs: T, @autoclosure rhs: () throws -> U) rethrows -> Bool
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句