Skip to content

Instantly share code, notes, and snippets.

@spf2
Created October 4, 2016 21:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spf2/df1e381d00527e45df1b9b94325d4530 to your computer and use it in GitHub Desktop.
Save spf2/df1e381d00527e45df1b9b94325d4530 to your computer and use it in GitHub Desktop.
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