class Foo { var callbacks: [() -> Void] = [] init() { callbacks.append(bar) print("foo: inited") } deinit { print("foo: deinit") } func bar() { } } let foo = Foo()