Skip to content

Instantly share code, notes, and snippets.

@cooler333
Last active June 2, 2020 15:16
Show Gist options
  • Save cooler333/f10bba26a04cbee849d03fd04da12781 to your computer and use it in GitHub Desktop.
Save cooler333/f10bba26a04cbee849d03fd04da12781 to your computer and use it in GitHub Desktop.
import Foundation
class MyView: CustomStringConvertible {
let index: UInt
var ID: String
init(withIndex index: UInt) {
self.index = index
ID = String(index)
}
var description: String {
return "(\(index), \(ID))"
}
}
class MyViewController {
var strings: [String] = []
var views: [MyView] = []
}
class FirstViewController: MyViewController { }
class SecondViewController: MyViewController { }
//
var firstVC = FirstViewController()
firstVC.strings = ["One", "Two", "Three"]
firstVC.views = [MyView(withIndex: 1), MyView(withIndex: 2), MyView(withIndex: 3)]
let secondVC = SecondViewController()
secondVC.strings = firstVC.strings
secondVC.views = firstVC.views
secondVC.strings.popLast()
print(firstVC.strings)
secondVC.views.popLast()
print(firstVC.views)
secondVC.views.last?.ID = "4"
print(firstVC.views)
/*
Question: what will be printed in console?
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment