我想快速创建一个使用通用闭包(块)的函数。
我的第一个尝试是这样做:
func saveWithCompletionObject(obj : AnyObject, success : AnyObject -> Void, failure : Void -> Void)
Run Code Online (Sandbox Code Playgroud)
但是,一旦我用另一个块调用此函数,例如:
func doSomething(success : String -> Void, failure : Void -> Void)
{
saveWithCompletionObject("Example", success, failure)
}
Run Code Online (Sandbox Code Playgroud)
我得到一个错误: 'AnyObject' is not a subtype of 'String'
提前致谢 !