Swift closure crashes when called as Objective-C block

大憨熊 提交于 2019-12-05 00:26:43

I figured it out with the help of the pop-up documentation! When dealing with Objective-C, most things will require a !. I'm pretty sure this is because Objective-C has no concept of Optionals like in Swift.

Instead of defining my closure as:

... self.myClass?.block = { (inString: String!) -> String in ...

It works when changing it to:

... self.myClass?.block = { (inString: String!) -> String! in ...

Which makes sense, because that is what is recommended in the pop-up documentation.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!