In the book, under the heading ‘After the drop’ there is a relatively small section on how to add the NSDragOperation.Delete “type” to the existing .Copy “type”, so that the user can drag the die to the trash and have it nil out intValue. This seemed very straightforward, but I had the darnedest time trying to get the bitwise OR line to work. Under Xcode 7.2 / Swift 2.0 I ran into the following compiler errors:
[ul]
[li]The original [color=#4040FF]return .Copy | .Delete[/color] causes error: [color=#BF0040]Type of expression is ambiguous without more context[/color].
[/li]
[li]Trying to be more specific… [color=#4040FF]return NSDragOperation.Copy | NSDragOperation.Delete[/color] causes error: [color=#BF0040]Binary operator ‘|’ cannot be applied to two ‘NSDragOperation’ operands[/color].
[/li]
[li]Trying rawValues… [color=#4040FF]return NSDragOperation.Copy.rawValue | NSDragOperation.Delete.rawValue[/color] causes error: [color=#BF0040]Cannot convert return expression of type ‘Uint’ to return type ‘NSDragOperation’[/color].
[/li]
[li]Trying Objective-C declared constants… [color=#4040FF]return NSDragOperationCopy | NSDragOperationDelete[/color] causes error: [color=#BF0040]Use of unresolved identifier ’NSDragOperationCopy’[/color] & [color=#BF0040]Use of unresolved identifier ’NSDragOperationDelete’[/color].
[/li]
[li]Finally trying this format…[color=#4040FF]return NSDragOperation.Copy.union(NSDragOperation.Delete)[/color] did seem to compile and work correctly. However it seems unnecessarily cumbersome and verbose for something that seems like it should be easy to express. What if you had to combine 3 or 4 values?[/li][/ul]
What is the proper shorthand format for combining values in Swift 2.0 analogous to the “return .Copy | .Delete”?