Created
April 24, 2018 07:42
-
-
Save vialyx/bb46659b2a9b6a1e4adad13bacc16b3c 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 Customer { | |
let udid: String | |
let name: String | |
init(udid: String, name: String) { | |
self.udid = udid | |
self.name = name | |
print("\(udid) initialized") | |
} | |
deinit { | |
print("\(udid) deinitialized") | |
} | |
} | |
// MARK: - Global strong reference. It'll be free up at the end of programm cycle. | |
var customer: Customer? = nil | |
customer = Customer(udid: "global reference", name: "Jo Mock") | |
/* | |
print: global reference initialized | |
*/ | |
customer = nil | |
// MARK: - Functin local reference. It'll be free up at the end of function. | |
func printCustomer() { | |
let customer = Customer(udid: "function printCustomer", name: "Jo Mock") | |
/* | |
print: function printCustomer initialized | |
*/ | |
print("print customer: \(customer.udid)") | |
/* | |
print: function printCustomer deinitialized | |
*/ | |
} | |
printCustomer() | |
// MARK: - Loop local reference. It'll be free up at the end of loop cycle. | |
for i in 0..<5 { | |
_ = Customer(udid: "loop \(i)", name: "Jo Mock") | |
/* | |
print: loop {i} initialized | |
print: loop {i} deinitialized | |
*/ | |
} | |
/* | |
print: global reference deinitialized | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment