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 }
2.1m questions
2.1m answers
60 comments
57.0k users