Last active
June 2, 2020 15:16
-
-
Save cooler333/f10bba26a04cbee849d03fd04da12781 to your computer and use it in GitHub Desktop.
This file contains 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
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