what does | or || mean in Swift?

2019-09-25 09:22发布

问题:

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



标签: ios xcode swift