Just some baseline questions.
In Objective-C, I was using enumerateObject and it made quite a performance difference.
After some porting, in Swift 2.3, I had code like ...
lotsOfStuff?.enumerateObjects(options: NSEnumerationOptions.concurrent) {
(item:Any!, idx:Int, stop:UnsafeMutablePointer<ObjCBool>) -> Void in
//work on stuff
}Looks like Xcode 8 / Swift 3 things changed more. I'm attempting now to move away for NSArray, NSMutableArray and Any. I see Swift's Array does not support enumerateObjects. I figure that implies we need to use gcd as an alternative?
//set up property
processingQueue = DispatchQueue(label:"com.someplace.somewhere", qos:.userInteractive, attributes:.concurrent)
//Process somewhere else in code...
let group = DispatchGroup()
for p in lotsOfStuff! {
processingQueue.async(group:group) {
//work on stuff. p/self retained should be ok
}
}
group.wait()I assume arc is going to handle dispatch_release now? So, when group falls out of scope or if the class is deinited then the queue will be destroyed?
Some more lingering questions about gcd. How many threads will it spawn if its concurrent? And will it ever choose main thread or does it always create new threads? Past documents never really said. I recall it has a thread pool internally. I know there is a main queue that can specifically target main thread execution.
Also, I remember in the past I could set the concurrent queue up to only process X items at a time. But not sure the new api has that -- seems like it will manage that for me which is fine. Did not seem like many attribues. There is just one to set concurrent and another to set initially inactive.
Watched latest wwdc video on gcd and it was informative.