iosobjective-cpropertiesoperatorsnot-operator

Can I use the ! operator on a property?


Is it possible to use the !(not, or bang) operator on a property? The reason I would want to do this is because I might find a property that does the exact opposite of what I want it to do. Here is an example of what I have in mind.

GKMatchRequest *request = [[GKMatchRequest alloc] init];
request.minPlayers = 2;
request.maxPlayers = 2;
request.!playerGroup = MyMap_Forest | MyRulesCaptureTheFlag;

I got this example from the Apple Docs and modified it.

Here is what the docs say:

If your game sets the playerGroup property, only players whose requests share the same playerGroup value are automatched by Game Center. Setting the playerGroup property to 0 allows the player to be matched into any waiting match. Set the playerGroup property to a nonzero number to match the player only with players whose match request shares the same player group number.


Solution

  • What you seem to want to do is not possible. The playerGroup property only has two possible semantics: if it's 0, then it matches anything; if it's any non-zero value, then it only matches requests with the same value.

    There's no way to achieve "matches anything except this value". That has nothing to do with the language or syntax. It's entirely on how Apple defined the playerGroup property. The semantics of this is in the implementation, both in the frameworks and on the server side. Hoping that some hypothetical language feature could induce different behavior in those pieces of code is not sensible.