gpt4 book ai didi

ios - 如何在 UITextView、Swift3 和 Parse 服务器上显示数组元素 (bitnami)

转载 作者:行者123 更新时间:2023-11-30 12:26:16 25 4
gpt4 key购买 nike

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

它终于按照我想要的方式工作了,但是看起来非常奇怪,我不明白为什么它工作得很好。

有谁能理解它为什么起作用吗?

  1. ViewController.swift

    query?.limit = 1

    query?.findObjectsInBackground(block: {(objects,error) in
    if let users = objects {

    for object in users {

    if let user = object as? PFUser {

    self.userName.text = user.username!


    if let userCarType = user["carType"] as? Array<Any>{


    self.carTypeText.text = userCarType[0] as! String


    }
  2. 解析服务器

列: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
    }
    }
    }
    }
    }
    }

    关于ios - 如何在 UITextView、Swift3 和 Parse 服务器上显示数组元素 (bitnami),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44171903/

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