What does | or || mean in Swift? I have come across them in some Swift tutorials.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
It is a bitwise OR
operator, as documented in The Swift Programming Language
回答2:
You can use bitwise-OR ( | ) together the constants that represent the particular aspects you want.Apple regularly use bit masks for allowing multiple values to be stored in a single variable. for example:autoresizingMask
view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
for more details
http://code.tutsplus.com/articles/understanding-bitwise-operators--active-11301 http://swinden.com/bitwise/
回答3:
This is Bitwise OR operation, but to enter your switch case your contactMask
has to be exactly the same that BodyType.boundary.rawValue | BodyType.sensorUp.rawValue
The condition is the same that : if contactMask & BodyType.boundary.rawValue && contactMask & BodyType.sensorUp.rawValue