gpt4 book ai didi

ios - Swift 中的 ObjC 委托(delegate)回调

转载 作者:可可西里 更新时间:2023-11-01 02:18:17 26 4
gpt4 key购买 nike

在 ObjC 中,我有一个函数声明为

-(void)fubar:(void(^)(NSDictionary *))callback;

这就是我将在 ObjC 中使用的方式

fubar(^(NSDictionary *dict) {
console.log(dict);
})

桥接后如何在 Swift 中使用相同的内容?

最佳答案

因为它是最后一个参数,所以它可以用作尾随闭包:

fubar { (dict) in
print(dict) // prints dictionary
}

甚至更短

fubar() { 
print($0) // prints dictionary
}

Read the section on Trailing Closures in Apple's Swift book for more info.

关于ios - Swift 中的 ObjC 委托(delegate)回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34370349/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com