gpt4 book ai didi

ios - Parse Cloud Code 中调用函数

转载 作者:行者123 更新时间:2023-11-30 13:30:31 25 4
gpt4 key购买 nike

我是第一次使用云代码,并尝试调用以下函数:

       let friendRequest: PFObject = self.friendRequestsToCurrentUser[sender.tag] as PFObject
let fromUser: PFUser = friendRequest[FriendRequestKeyFrom] as PFUser
//call the cloud code function that adds the current user to the user who sent the request and pass in the friendRequest id as a parameter
PFCloud.callFunctionInBackground("addFriendToFriendsRelation", withParameters: ["friendRequest": friendRequest.objectId]) { (object:AnyObject!, error: NSError!) -> Void in
let friendsRelation: PFRelation = PFUser.currentUser()!.relationForKey("friends")
friendsRelation.addObject(fromUser)
self.currentUser.saveInBackgroundWithBlock({ (succeeded: Bool, error: NSError!) -> Void in
if succeeded {
} else {
}
})
}
}

实现该功能后,我需要添加“!”到参数中的 objectId 来解包它。但是,这样做会给我带来错误:

Cannot convert value of type '(AnyObject!, NSError!) -> Void' to expected argument type 'PFIdResultsBlock?'

为了调用这个函数我必须改变什么?

最佳答案

PFIdResultsBlock 对应于以下签名 (AnyObject?, NSError?) -> Void,因此请尝试将您的代码更改为:

let friendRequest: PFObject = self.friendRequestsToCurrentUser[sender.tag] as PFObject
let fromUser: PFUser = friendRequest[FriendRequestKeyFrom] as PFUser

//call the cloud code function that adds the current user to the user who sent the request and pass in the friendRequest id as a parameter
PFCloud.callFunctionInBackground("addFriendToFriendsRelation", withParameters: ["friendRequest": friendRequest.objectId]) { (object:AnyObject?, error: NSError?) -> Void in
let friendsRelation: PFRelation = PFUser.currentUser()!.relationForKey("friends")
friendsRelation.addObject(fromUser)
self.currentUser.saveInBackgroundWithBlock({ (succeeded: Bool, error: NSError!) -> Void in
if succeeded {

} else {

}
})
}

关于ios - Parse Cloud Code 中调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36612317/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com