manojlds answer is correct, and so I accepted it.
However, a few days ago there was a similar answer with the same solution, but with a different argument (now it is deleted).
The argument was that the compiler cannot know whether the protocol is used for a class, structure, or enumeration. With Swift, protocols can be applied to all of these types. But instances of the structure use a call by value, and for instances of classes (objects) it is a call by reference.
From my point of view, this answer was also correct, because you can solve the problem with the second solution:
@objc protocol Flag { var flag: Bool {get set} }
Just add @obj attriute to the protocol. As a result, you can use this protocol only for classes that produce results, only by-refernece calls are allowed. Therefore, the compiler no longer needs inout information.
But I was looking for a solution to increase protocol reuse and now using manojlds suggestions.
source share