fabian fabian - 27 days ago 6
Swift Question

What is the Swift equivalent for dispatch_group_create

How do I wait for several methods to be completed?

This is the objective-c solution:

self.dispatch_group = dispatch_group_create();
dispatch_group_notify(self.dispatch_group, dispatch_get_main_queue(), ^{
});
dispatch_group_leave(strongSelf.dispatch_group);

Answer

Swift is mostly compatible to Objective-C and I have no issues with this code:

let dispatch_group = dispatch_group_create()
dispatch_group_notify(dispatch_group, dispatch_get_main_queue()) { }
dispatch_group_leave(dispatch_group)

There's an Apple document about transferring your Objective-C code to Swift: https://developer.apple.com/library/prerelease/ios/documentation/swift/conceptual/buildingcocoaapps/Migration.html

Comments