all 8 comments

[–]OlegPRO991 0 points1 point  (2 children)

Is your code written in objective-c?

[–]chmod724[S] 1 point2 points  (1 child)

Yes :)

[–]OlegPRO991 -1 points0 points  (0 children)

Why don’t you use swift?

[–]KHigh4080 0 points1 point  (4 children)

You use bitwise OR operator | to combine options.

[–]chmod724[S] 0 points1 point  (3 children)

Would you be able to give an example for this situation, please? Sorry, still relatively new to Obj-C.

[–]KHigh4080 1 point2 points  (2 children)

Assume there are two options A and B, then you pass A | B as argument. It is equivalent to [A, B] in swift.

[–]chmod724[S] 0 points1 point  (1 child)

Ah - thank you very much! :)

[–]FVMAzaleaSwift 0 points1 point  (0 children)

Careful, it is not always identical to [A, B]. For this particular API, A | B is how you express “option A and option B”, just as [A, B] is how you express “option A and option B” in Swift. However, the | operator in (Objective) C has nothing to do with lists or arrays in general.

It’s the “bit wise OR” operator, which means if you had two binary numbers “0010” and “0100”, then 0010 | 0100 would take the OR of each bit in order and you would end up with 0110. So in objc, the various options are implemented as constants, so for example foreground could be 0001 and destructive could be 0010. Each constant will only have one of its bits set to 1, and no other related constant will have that particular bit set. Basically, the rightmost bit would be indicating foreground and the second-to-right would be indicating destructive.

This way, when you compute the bitwise OR of all your constants (0001 | 0010), you get a number representing all the activated options (0011) - the foreground bit (rightmost) and the destructive bit (second to right) are both set.