Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 目标C到Swift方法调用?_Objective C_Swift - Fatal编程技术网

Objective c 目标C到Swift方法调用?

Objective c 目标C到Swift方法调用?,objective-c,swift,Objective C,Swift,这是我的objective c方法调用,我需要将其转换为swift调用 它抱怨“找不到接受所提供参数的logInWithUsernameInBackground的重载 我做错了什么 目的C法脱毒 typedef void (^PFUserResultBlock)(PFUser *user, NSError *error); + (void)logInWithUsernameInBackground:(NSString *)username

这是我的objective c方法调用,我需要将其转换为swift调用

它抱怨“找不到接受所提供参数的logInWithUsernameInBackground的重载

我做错了什么

目的C法脱毒

typedef void (^PFUserResultBlock)(PFUser *user, NSError *error);

+ (void)logInWithUsernameInBackground:(NSString *)username
                             password:(NSString *)password
                                block:(PFUserResultBlock)block;
目标C呼叫

[User logInWithUsernameInBackground:@""
                            password:@""
                               block:^(PFUser *user, NSError *error) {
     NSLog(@"test");
 }];
迅捷的


让编译器通过类型推断为您找出正确的类型

User.logInWithUsernameInBackground("", 
  password: "", 
     block: {
     (user, error) in
         NSLog("test")
    } 
)

请在Objective-C中显示此方法的声明。重要的不是您如何调用它。
{(用户,错误)在NSLog(“测试”)中)
将方法定义添加到我的question@BryanChen你能把它作为一个答案提交给我吗?Objective c用来为你自动完成块定义。在swift中闭包似乎不会发生这种情况
User.logInWithUsernameInBackground("", 
  password: "", 
     block: {
     (user, error) in
         NSLog("test")
    } 
)