简体   繁体   中英

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:



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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM