Last active
December 14, 2016 21:26
-
-
Save pxpgraphics/4cfb7e02b6be7a583bf5f8a3ccbcd29a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
//: 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