Created
October 4, 2016 21:23
-
-
Save spf2/df1e381d00527e45df1b9b94325d4530 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
@objc protocol FooProtocol { | |
var bar: Set<String> { get set } | |
} | |
class Foo : FooProtocol { | |
var bar = Set<String>() | |
} | |
func toggle(foo: inout FooProtocol, item: String) { | |
if !foo.bar.contains(item) { | |
foo.bar.insert(item) | |
} else { | |
foo.bar.remove(item) | |
} | |
} | |
var a: FooProtocol = Foo() | |
toggle(foo: &a, item: "x") | |
print(a.bar) | |
toggle(foo: &a, item: "x") | |
print(a.bar) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment