iosswiftspinlock

'OSSpinLock' was deprecated in iOS 10.0: Use os_unfair_lock() from <os/lock.h> instead


I went through this Question but the provided solution didn't work. Can someone please explain any alternative approach or proper implementation using os_unfair_lock()?

when I am using 'OS_UNFAIR_LOCK_INIT', it seems unavailable.

enter image description here

Thanks!


Solution

  • Below solution isn't recommended from iOS 16+ as per the documentation here

    You can use os_unfair_lock as below,

    var unfairLock = os_unfair_lock_s()
    
    os_unfair_lock_lock(&unfairLock)
    os_unfair_lock_unlock(&unfairLock)