Swift 2 - completion block syntax when using in Obj-C

OdieO

I have this Swift block:

var onLoggedIn: ((sender:AnyObject?, showFTUE:Bool) -> ())?

Trying to use it in Obj-C, and XCode 7 autocompletes as:

 [loginController setOnLoggedIn:^(id _Nullable, BOOL) {
        <#code#>
    }];

But then throws an error and tells me parameter name is omitted. I tried inserted the parameter showFTUE in various positions with no luck.

In my Swift translation file it's translated as:



sunshinejr

Since Xcode 7, when your completion block declared in .h (in obj-c) doesn't have names (which is default autocomplete behavior from Xcode 7) it will also autocomplete without parameter names. As you can see your block has only types and _Nullable directive, just add parameter names at the end.

[loginController setOnLoggedIn:^(id _Nullable parameterName1, BOOL parameterName1) {
        <#code#>
}];

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Using Obj-C completion block in Swift

Completion block syntax when no data passed in Swift

Swift SceneKit: SCNAudioPlayer completion block (didFinishPlayback) syntax?

Using a Swift completion block with a nullable String value in Objective-C

Completion Block AFNetworking in Swift

Return in Completion Block Swift

Swift completion block

Completion Blocks Syntax in Swift

Syntax for Calling Method with Completion in Swift using Singleton Pattern

Block syntax translation problems Objective C to Swift

How to Write Unit test of a async method without completion Block in Obj C

Using Obj-C that relies on other Obj-C in Swift?

Constraints not working when using block syntax in Rails

Function with optional completion block in Swift

Using obj-c typedef in Swift

Is `use_frameworks!` necessary when using a pod which uses swift internally, but publically is obj-c?

Swift 2 functions completion

Overriding Obj-C-methods in Swift using Swift enums

How to write this objective-c block in swift syntax?

Swift Error Message with a Firebase completion block

Swift firebase createUser function completion block

Swift HTTP Request Completion Block not Working Properly

How To Finish Completion Block - Swift / Stripe Payments

Swift - How to handle completion block in for-loop?

pass completion block from swift to back to objective

Completion Block becomes nil in Swift 3

Swift completion block with success and failure handler

How to add objects to array at specific index in async completion block using Swift

Middleman shows syntax error when using a link_to block