簡體   English   中英

解析查詢包裝錯誤,在設備上的模擬器崩潰時可以正常工作

[英]Parse Query Wrapping Error, works fine on simulator crashes on device

下面的代碼在模擬器上運行正常,然后在兩台設備上崩潰並在一台設備上工作。

我也得到這個:

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

可能與將obj-C橋接到我的快速應用程序中有關嗎? 有什么建議么

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
}

您想在后台執行查詢,以便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!)")
        }
    }
}

我要看的第一個地方是強制打開可選項。 其中的每一個都要求崩潰—當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)
              }
          }
      }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM