【问题标题】:Parse Query Wrapping Error, works fine on simulator crashes on device解析查询包装错误,在设备上的模拟器崩溃时工作正常
【发布时间】:2015-09-01 21:22:47
【问题描述】:

下面的代码在模拟器上运行良好,然后在两台设备上崩溃并在一台设备上运行。

我也得到了这个:

function signature specialization <Arg[0] = Exploded, Arg[1] = Exploded> of Swift.(_fatalErrorMessage (Swift.StaticString, Swift.StaticString, Swift.StaticString, Swift.UInt) -> ()).(closure #2)

这可能与将 obj-C 桥接到我的 swift 应用程序中有关吗? 任何建议

var query = PFUser.query()
query?.whereKey("username", notEqualTo: PFUser.currentUser()!.username!)
var users = query?.findObjects()

//Loop through users
if let users = users as? [PFUser]{
    for user in users {
        //println(user.username)
        self.userArray.append(user.username!)
    }
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! UITableViewCell

    // Configure the cell...

    cell.textLabel?.text = userArray[indexPath.row]

    return cell
}

【问题讨论】:

    标签: ios swift parse-platform


    【解决方案1】:

    您希望在后台执行查询,以便 UI(主线程)保持响应。请尝试以下操作:

    if let currentUsername = PFUser.currentUser()?.username {
        var query = PFUser.query()!
        query.whereKey("username", notEqualTo: currentUsername)
        query.findObjectsInBackgroundWithBlock { (objects: [AnyObject]?, error: NSError?) -> Void in
            if (error == nil) {
                if let users = objects as? [PFUser] {
                    for user in users {
                        self.userArray.append(user.username!)
                    }
                }
            } else {
                // Log details of the failure
                println("query error: \(error) \(error!.userInfo!)")
            }
        }
    }
    

    【讨论】:

    • 以下行: if let currentUsername = PFUser.currentUser()?.username? ?必须后跟调用、成员查找或下标
    • 删除 ?在用户名之后,它可以工作。我会更正之前的帖子
    • 我删除了 ?在用户名之后,但是用户不加载
    • 尝试添加一些 println() 语句来找出出错的地方。使用 Parse 时,除非您使用 facebook/twitter 登录,否则不会自动设置用户名字段。
    • 我添加了 println(user.username) 及其打印: Optional("foo") Optional("test")
    【解决方案2】:

    我首先要看的是强制解包选项。每个人都在要求崩溃——当PFUser.currentUser() 返回 nil 并且 user.username 返回 nil 时:

    试试:

       var query = PFUser.query()
       if let query = query, 
       currentUser = PFUser.currentUser() as? PFUser, 
       currentUsername = currentUser.username {
          query.whereKey("username", notEqualTo: currentUsername)
          var users = query.findObjects()
    
          //Loop through users
          if let users = users as? [PFUser]{
               for user in users {
                   //println(user.username)
                  if let username = user.username {
                       self.userArray.append(username)
                  }
              }
          }
    

    【讨论】:

    • PFUser 有一个沮丧的问题
    猜你喜欢
    • 2021-10-19
    • 1970-01-01
    • 2013-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-06
    相关资源
    最近更新 更多