Saturday, November 21, 2026
HomeiOS Developmentios - Why primitive integer can't be handed as a thread parameter?

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 acquired is just not as identical because the one handed in Thread.init(). If I exploit string to hold the parameter, the worth acquired 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]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments