2016-01-13 32 views
2

我有一个块的目标C块的目标C文件中声明是这样的:使用封闭斯威夫特被宣布为雨燕2.1

- (void) getUserCurrentProfile:(void (^)(UserInfo *userInfo,NSError * error)) callBack { 
if ([FBSDKAccessToken currentAccessToken]) { 
    //code here 
    }]; 
} 
斯威夫特文件

我把它叫做:

func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) { 
FBManager.getUserCurrentProfile({(userInfo:UserInfo?, error:NSError?) -> Void in 
    appDelegate.showHomeView() 
}) 

但我完全重新得到这个错误:

enter image description here

任何人都可以GI让我知道吗?

P/S:我读过这个问题:Swift : Use closure compatible with Objective-C block。并做同样的事情。但它不起作用

回答

1

getUserCurrentProfile是一种实例方法,您将其称为类方法。你应该(也许sharedInstance?)调用它的FBManager一个实例:

FBManager.sharedInstance.getUserCurrentProfile { userInfo, error in) 
    appDelegate.showHomeView() 
} 

错误说,它不能关闭转换为FBManager,而且是正确的,因为你调用它作为一类功能和编译器期望和实例操作。上述呼叫也可以写在咖喱函数调用中:

FBManager.getUserCurrentProfile(FBManager.sharedInstance) { userInfo, error in) 
    appDelegate.showHomeView() 
}