[英]Swift closure syntax using Shark Food Mute Switch?
I am having trouble with swift closure syntax. 我在使用快速关闭语法时遇到麻烦。 I am trying to check the mute switch using Sharkfood which you can see here: http://sharkfood.com/content/Developers/content/Sound%20Switch/
我正在尝试使用Sharkfood检查静音开关,您可以在此处查看: http ://sharkfood.com/content/Developers/content/Sound%20Switch/
The Block I'm trying to call is shown below. 我正在尝试调用的块如下所示。
typedef void(^SharkfoodMuteSwitchDetectorBlock)(BOOL silent);
This is how I'm trying to call it but it isn't working. 这就是我试图称之为的方式,但是它没有用。 I've tried a ton of different ways and I know I'm missing something little since I'm new to swift.
我已经尝试了很多不同的方法,而且我知道自从我快速接触以来就缺少了一些东西。 The error I'm getting is:
我得到的错误是:
'(Bool) -> Void' is not convertible to 'Bool'
'(Bool)-> Void'不能转换为'Bool'
On the first line of this code: 在此代码的第一行:
muteDetector.silentNotify({
(silent: Bool) -> Void in
println("this")
println("worked")
})
Any help would be greatly appreciated. 任何帮助将不胜感激。
Never used that library, but looking at the documentation linked in your question I notice that silentNotify
is a property: 从未使用过该库,但是在查看问题中链接的文档时,我注意到
silentNotify
是一个属性:
@property (nonatomic,copy) SharkfoodMuteSwitchDetectorBlock silentNotify;
containing the block, so the error stating that a BOOL is expected makes sense. 包含该代码块,因此表明需要BOOL的错误是有道理的。
Instead with your code you are probably trying to call this method: 而是使用您的代码,您可能正在尝试调用此方法:
-(void)setSilentNotify:(SharkfoodMuteSwitchDetectorBlock)silentNotify{
_silentNotify = [silentNotify copy];
self.forceEmit = YES;
}
I don't know which of the 2 you are attempting to do - if you want to call the block, then you have to just provide a bool: 我不知道您要尝试使用哪两个方法-如果您要调用该块,则只需要提供一个布尔值即可:
muteDetector.silentNotify(true)
if instead you want to register a new block (closure), then you have to use: 相反,如果您想注册一个新块(关闭),则必须使用:
muteDetector.setSilentNotify({
(silent: Bool) -> Void in
println("this")
println("worked")
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.