I've searched the Swift book, but can't find the Swift version of @synchronized. How do I do mutual exclusion in Swift?
You can use GCD. It is a little more verbose than @synchronized, but works as a replacement:
@synchronized
let serialQueue = DispatchQueue(label: "com.test.mySerialQueue") serialQueue.sync { // code }
1.4m articles
1.4m replys
5 comments
57.0k users