interview:developer:ios:start

iOS Developer Interview

  • Consider the following code. What's the value of the len variable, and why?
  • 参考以下的代码,len的值为何?请解释。
var array1 = [1, 2, 3, 4, 5]
var array2 = array1
array2.append(6)
var len = array1.count
  • Consider the following code. Where is the error and why? How can it be fixed?
  • 参考以下的代码,那里出错了?请解释。如何修复?
let op1: Int = 1
let op2: UInt = 2
let op3: Double = 3.34
var result = op1 + op2 + op3
  • Consider the following code. What is the bug and how does it affect memory? How can it be fixed?
  • 参考以下的代码,那里出错了以及如何影响内存?如何修复?
class Master {
    lazy var detail: Detail = Detail(master: self)
    
    init() {
        println("Master init")
    }
    
    deinit {
        println("Master deinit")
    }
}

class Detail {
    var master: Master
    
    init(master: Master) {
        println("Detail init")
        self.master = master
    }
    
    deinit {
        println("Detail deinit")
    }
}

func createMaster() {
    var master: Master = Master()
    var detail = master.detail
}
    
createMaster()
  • Consider the following UITableViewCell constructor. What is the purpose of the reuseIdentifier? What is the advantage of setting it to a non-nil value?
  • 参考以下UITableViewCell构造数,reuseIdentifier的作用是什麽?把它设定为non-nil值有什麽好处?
init(style: UITableViewCellStyle, reuseIdentifier: String?)
  • Write down the log results at 3 different cases
    • Start MainViewController
    • Push to ViewControllerTwo from MainViewController
    • User press back button from ViewControllerTwo
  • 我们有以下兩段代码,请分别写下以下三种执行后log的结果
    • 开始 MainViewController
    • MainViewController 推向 ViewControllerTwo
    • 用户在 ViewControllerTwo 按back button
class MainViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        print("MainViewController :", "viewDidLoad")
    }
    
    override func viewWillLayoutSubviews() {
        super.viewWillLayoutSubviews()
        print("MainViewController :", "viewWillLayoutSubviews")
    }
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        print("MainViewController :", "viewDidLayoutSubviews")
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        print("MainViewController :", "viewWillAppear")
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        print("MainViewController :", "viewDidAppear")
    }

    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        print("MainViewController :", "viewWillDisappear")
    }
    
    override func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)
        print("MainViewController :", "viewDidDisappear")
    }
    
    deinit {
        print("MainViewController :", "deinit")
    }
}
class ViewControllerTwo: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        print("ViewControllerTwo :", "viewDidLoad")
    }
    
    override func viewWillLayoutSubviews() {
        super.viewWillLayoutSubviews()
        print("ViewControllerTwo :", "viewWillLayoutSubviews")
    }
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        print("ViewControllerTwo :", "viewDidLayoutSubviews")
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        print("ViewControllerTwo :", "viewWillAppear")
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        print("ViewControllerTwo :", "viewDidAppear")
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        print("ViewControllerTwo :", "viewWillDisappear")
    }
    
    override func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)
        print("ViewControllerTwo :", "viewDidDisappear")
    }
    
    deinit {
        print("ViewControllerTwo :", "deinit")
    }
}
  • interview/developer/ios/start.txt
  • Last modified: 2018/06/04 12:37
  • by don.lee