ios – Why primitive integer can’t be handed as a thread parameter?


In my swift code, I begin a thread with an integer parameter. However I discovered the thread operate obtained is just not as similar because the one handed in Thread.init(). If I take advantage of string to hold the parameter, the worth obtained is identical as I handed.

That is my code:

    @objc func run_with_uint(param: UInt) {
        os_log("run_with_uint: %ld", param)
    @objc func run_with_str(param: String) {
        os_log("run_with_str: %s", param)
    func onStartClick(sender: UIButton) {
        let param: UInt = 12345678
        let t1 = Thread.init(goal: self, selector: #selector(run_with_uint), object: param)
        let t2 = Thread.init(goal: self, selector: #selector(run_with_str), object: String(param))

output is:

run_with_uint: -6705266956350674278
run_with_str: 12345678



Leave a Reply