Ios 如何在UITextView、Swift3&;上显示数组元素;解析服务器(bitnami)

Ios 如何在UITextView、Swift3&;上显示数组元素;解析服务器(bitnami),ios,arrays,swift,parse-platform,Ios,Arrays,Swift,Parse Platform,我是swift/Parse服务器新手,正在努力显示存储在Parse服务器中的数组元素(bitnami) 它最终按我所希望的那样工作,但它看起来非常奇怪,我不明白为什么它工作得很好 有没有人能理解它为什么起作用 ViewController.swift query?.limit=1 query?.findObjectsInBackground(块:{(对象,错误)在 如果让用户=对象{ 对于用户中的对象{ 如果让用户=对象为PFUser{ self.userName.text=user.user

我是swift/Parse服务器新手,正在努力显示存储在Parse服务器中的数组元素(
bitnami

它最终按我所希望的那样工作,但它看起来非常奇怪,我不明白为什么它工作得很好

有没有人能理解它为什么起作用

  • ViewController.swift

    query?.limit=1
    query?.findObjectsInBackground(块:{(对象,错误)在
    如果让用户=对象{
    对于用户中的对象{
    如果让用户=对象为PFUser{
    self.userName.text=user.userName!
    如果让userCarType=user[“carType”]作为数组{
    self.carTypeText.text=userCarType[0]作为!字符串
    }
    
  • 解析服务器

  • 列:carType(数组)

    价值:“丰田,福特”

  • 它在UITextField上的显示方式:

  • 丰田,福特

    下面是代码的一些解释,如果您需要更多解释,请让我知道

        let query = PFQuery(className:"UserCarTypes") /// name of your table
        query.includeKey("UserPointer") // if you have pointers like user (and you want to load this data also)
        query.whereKey("x", equalTo: false) // set some conditions in query if needed
        query.findObjectsInBackground { (objects: [PFObject]?, error: Error?) in
    
            // query always returns the objects (rows) in a [PFObject] array
    
            // first check for error or nil
            if error != nil {
                print(error!)
                return
            }
    
            if objects?.count == 0 || objects == nil {
                print("no data retrieved")
                return
            }
    
            //loop throught objects
            if let users = objects {
                for object in users {
    
                    //set user label
                    if let user = object as? PFUser {
                        self.userName.text = user.username! // set username on text label (this assumes there is always a username, otherwise your app will crash)
    
                    }
    
                    //set carType label
                    if let userCarType = user["carType"] as? NSArray { // downcast the row data from the PFObject to an Array
                        if let first_car = userCarType[0] as? String { // set the first value of your array of userCarType: Toyota
                            if let second_car = userCarType[1] as? String { // set the second value of your array: Ford
                                self.carTypeText.text = "\(first_car),\(second_car)" // set both car types on the TextLabel
                            } else {
                                self.carTypeText.text = "\(first_car)" // set only the first car type on the TextLabel
                            }
                        }
                    }
                }
            }
        }
    
        let query = PFQuery(className:"UserCarTypes") /// name of your table
        query.includeKey("UserPointer") // if you have pointers like user (and you want to load this data also)
        query.whereKey("x", equalTo: false) // set some conditions in query if needed
        query.findObjectsInBackground { (objects: [PFObject]?, error: Error?) in
    
            // query always returns the objects (rows) in a [PFObject] array
    
            // first check for error or nil
            if error != nil {
                print(error!)
                return
            }
    
            if objects?.count == 0 || objects == nil {
                print("no data retrieved")
                return
            }
    
            //loop throught objects
            if let users = objects {
                for object in users {
    
                    //set user label
                    if let user = object as? PFUser {
                        self.userName.text = user.username! // set username on text label (this assumes there is always a username, otherwise your app will crash)
    
                    }
    
                    //set carType label
                    if let userCarType = user["carType"] as? NSArray { // downcast the row data from the PFObject to an Array
                        if let first_car = userCarType[0] as? String { // set the first value of your array of userCarType: Toyota
                            if let second_car = userCarType[1] as? String { // set the second value of your array: Ford
                                self.carTypeText.text = "\(first_car),\(second_car)" // set both car types on the TextLabel
                            } else {
                                self.carTypeText.text = "\(first_car)" // set only the first car type on the TextLabel
                            }
                        }
                    }
                }
            }
        }