gpt4 book ai didi

jquery - 快速捕获中 Unresolved 已识别错误

转载 作者:行者123 更新时间:2023-12-03 08:53:50 25 4
gpt4 key购买 nike

多亏了社区,我昨天才解决了在转为Swift 2时的错误处理问题。这些更正实际上产生了一个新错误,我不知道如何纠正。以下是当前代码,该代码显示了Feed中的一些图片帖子:

override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)

ParseHelper.timelineRequestForCurrentUser {
(result: [AnyObject]?, error: NSError?) -> Void in
self.posts = result as? [Post] ?? []

for post in self.posts {
do
{
let data = try post.imageFile?.getData()
}
catch
{
print("Error: \(error)")
//Handle the error instead of print probably
}
post.image = UIImage(data: data!, scale:1.0) --> where I get the error message "Use of unresolved identified 'data'"

}

self.tableView.reloadData()
}

此外,我在前面的方法中引用的ParseHelper文件中出现一个新错误。
static func timelineRequestForCurrentUser(completionBlock: PFArrayResultBlock) {
let followingQuery = PFQuery(className: "Follow")
followingQuery.whereKey("fromUser", equalTo:PFUser.currentUser()!)

let postsFromFollowedUsers = Post.query()
postsFromFollowedUsers!.whereKey("user", matchesKey: "toUser", inQuery: followingQuery)

let postsFromThisUser = Post.query()
postsFromThisUser!.whereKey("user", equalTo: PFUser.currentUser()!)

let query = PFQuery.orQueryWithSubqueries([postsFromFollowedUsers!, postsFromThisUser!])
query.includeKey("user")
query.orderByDescending("createdAt")

// 3
query.findObjectsInBackgroundWithBlock(completionBlock) --> I get an error message too here "Cannot convert value of type 'PFArrayResultBlock' to expected argument type 'PFQueryArrayResultBlock?'"

最佳答案

对Swift不太熟悉,但是编译器的输出很有意义。首先,let data声明的范围限于do/catch的do块。为了使catch块使用数据,必须在do/catch范围内重新声明数据。

let data : NSData? // assuming type is NSData (my point here is about scope)
do {
data = try post.imageFile?.getData()
} catch {
print("Error: \(error)")
//Handle the error instead of print probably
}
// now data is in scope here...
post.image = UIImage(data: data!, scale:1.0)

第二个问题似乎是在这里将完成块声明为 PFArrayResultBlock类型的函数参数:
static func timelineRequestForCurrentUser(completionBlock: PFArrayResultBlock)

...但是parse希望将 PFQueryArrayResultBlock类型的块传递给 findObjectsInBackground。两者之间的区别似乎是数组元素的预期类型略有不同(查询的 [PFObject]?[AnyObject]?)。

关于jquery - 快速捕获中 Unresolved 已识别错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33438526/

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