Xcode 8 :function types cannot have argument label breaking my build

The Swift designers decided to prohibit argument labels for function types. The reasoning is explained here: https://github.com/apple/swift-evolution/blob/master/proposals/0111-remove-arg-label-type-significance.md This is a frustrating and questionable choice, as prohibiting argument labels makes it much easier to incorrectly invoke closures, which seems more important than simplifying the language’s type system. Usability > ideology.

How could I create a function with a completion handler in Swift?

Say you have a download function to download a file from network, and want to be notified when download task has finished. typealias CompletionHandler = (success:Bool) -> Void func downloadFileFromURL(url: NSURL,completionHandler: CompletionHandler) { // download code. let flag = true // true if download succeed,false otherwise completionHandler(success: flag) } // How to use it. downloadFileFromURL(NSURL(string: … Read more

Returning method object from inside block

You can’t. Embrace the fact that what you’re trying to do is asynchronous and add a completion block parameter to your getMyData method which is called when the inner completion handler is called. (And remove the return from the method signature): – (void)getMyDataWithCompletion:(void(^)(NSData *data))completion { MyUIDocument *doc = [[MyUIDocument alloc] initWithFileURL:fileURL]; [doc openWithCompletionHandler:^(BOOL success) { … Read more

tech