Skip to content

Instantly share code, notes, and snippets.

@pxpgraphics
Last active December 14, 2016 21:26
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 pxpgraphics/4cfb7e02b6be7a583bf5f8a3ccbcd29a to your computer and use it in GitHub Desktop.
Save pxpgraphics/4cfb7e02b6be7a583bf5f8a3ccbcd29a to your computer and use it in GitHub Desktop.
//: Playground - noun: a place where people can play
import UIKit
class ClinetSession {
static func shared() -> ClinetSession { return ClinetSession() }
private init() { }
}
class Clinet {
weak var delegate: ClinetDelgate?
init(_ session: ClinetSession) { }
}
protocol ClinetDelgate: class { }
class Foo: ClinetDelgate {
lazy var str: String! = "Bar"
lazy var aClient: Clinet! = {
var _aClient = Clinet(ClinetSession.shared())
_aClient.delegate = self
return _aClient
}()
// ...
func bar() {
print("pre nil: \(aClient) \(str)") // pre nil: Optional(Clinet) Optional("Bar")
aClient = nil // Foo
print("post nil: \(aClient) \(str)") // post nil: Optional(Clinet) Optional("Bar")
}
}
let foo = Foo() // Foo
foo.str // "Bar"
foo.bar() // Foo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment