gpt4 book ai didi

swift - 设置指向用 Swift 解析的指针

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

我有一个用户搜索一所学校,然后点击他们想要的学校。在 cellForRowAtIndexPath 中,我查询所选学校并获取其 objectId。然后,我将 objectId 设置为 PFUser.currentUser 中的指针“school_name”。指针指向“Schools”类,其中列出了所有学校。我收到一条错误消息“key school_name 的类型无效,预期是 *Schools,但得到了字符串(代码:111,版本:1.12.0)”。我似乎无法绕过它,因为 objectId 是一个字符串。我什至可以打印得到正确的 objectId。

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
{

let spinningActivity = MBProgressHUD.showHUDAddedTo(self.view, animated: true)
spinningActivity.labelText = "Just a Moment"
spinningActivity.detailsLabelText = "Adding Details"

let schoolIndexPath = tableView.indexPathForSelectedRow!
let selectedCell = tableView.cellForRowAtIndexPath(schoolIndexPath)! as UITableViewCell
let school : String = String(selectedCell.textLabel!.text!)

let schoolObjectIdQuery = PFQuery(className:"Schools")
schoolObjectIdQuery.whereKey("school_name", matchesRegex: school)



let query = PFQuery.orQueryWithSubqueries([schoolObjectIdQuery])

if reachabilityStatus == kNOTREACHABLE {

spinningActivity.hide(true)



self.displayAlert("No Internet Connection", message: "Please connect to the internet before continuing.")


} else {

query.findObjectsInBackgroundWithBlock {
(results: [PFObject]?, error: NSError?) -> Void in

if error != nil {

self.displayAlert("Error", message: error!.localizedDescription)

}

if let objects = results {

self.searchResults.removeAll(keepCapacity: false)

for object in objects {

let schoolObjectId = object.objectId!

let addDetails : PFUser = PFUser.currentUser()!

// let schoolObjectIdFormatted = PFObject(withoutDataWithClassName: "school_name", objectId: schoolObjectId)

addDetails.setObject(schoolObjectId, forKey: "school_name")

print(school)
print(schoolObjectId)

addDetails.saveInBackgroundWithBlock({ (success:Bool, error:NSError?) -> Void in



if error != nil {

spinningActivity.hide(true)

self.displayAlert("Error", message: error!.localizedDescription)

}

if success {

spinningActivity.hide(true)

self.dismissViewControllerAnimated(true, completion: nil)

print("Success")

}

})



}



}
}
}

}

最佳答案

因为您尝试使用指针...而不是字符串。您需要保存整个学校对象,而不是保存 objectId。

关于swift - 设置指向用 Swift 解析的指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35879790/

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