OdieO
OdieO

Reputation: 6994

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

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:



Upvotes: 1

Views: 130

Answers (1)

sunshinejr
sunshinejr

Reputation: 4854

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#>
}];

Upvotes: 1

Related Questions