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

[ad_1]

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)
    }
    
    @IBAction
    func onStartClick(sender: UIButton) {
        let param: UInt = 12345678
        let t1 = Thread.init(goal: self, selector: #selector(run_with_uint), object: param)
        t1.begin()
        let t2 = Thread.init(goal: self, selector: #selector(run_with_str), object: String(param))
        t2.begin()
    }

output is:

run_with_uint: -6705266956350674278
run_with_str: 12345678

Why?

[ad_2]

Leave a Reply