Junior — Senior
What will be displayed in example №8
livecode
Task condition
In the example, two subclasses of the base controller are created, arrays of strings and objects are filled, and then one controller gets references to the arrays of the other. Then, the method to remove the last element from the string array is called. Determine which values will remain in the arrays after the code executes.
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 {}
let 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()