是否可以在 Parse 中创建特定对象的数组?

Is it possible to create an Array of specific Objects in Parse?

我做了一个二维码扫描App,我手动把一些二维码解析进去让它识别,扫过的二维码没有解析的就不会识别。

唯一能区分它们的是它们的(信息),即 "restaurant"、"nail salon" 等

我正在寻找一种能够记录所选 QRCode 被扫描次数的整数的方法,然后将其放置在应用程序的标签上。

我可以(.count)用户保存和扫描的所有二维码,但似乎无法弄清楚如何将所有 "Nail Salons" 放入他们自己的数组中进行解析或 运行一个For循环匹配我需要的。

 // The code below will retrieve everything in the "info" column and print it to console
 // This prints "Nails Salon" x 5, "Restaurant" x3 and "Coffee Shop" x 7 in the order that they were scanned (Unorganised)
 // What block of code could I make to display what PFuser.current currently has in their parse?
 // E.g. PFUser has scanned "Nail Salon" 5 Times, "Restaurant" 3 time etc etc

    let infoCheck = PFQuery(className: "UserQRCodes")
    infoCheck.whereKey("info", contains: "")
    infoCheck.findObjectsInBackground { (objects: [PFObject]?, error: Error?) in
        if let error = error {

            print(error.localizedDescription)
        } else if let objects = objects {

            print(objects)
        }

    }

// To retrieve everything the USER has scanned and display it as String on the APP


let query = PFQuery(className: "UserQRCodes")
    query.whereKey("userName", equalTo: PFUser.current()!)
    query.findObjectsInBackground { (objects: [PFObject]?, error: Error?) in
        if let error = error {
            //log details of the failure
            print(error.localizedDescription)
        } else if let objects = objects {
            let stampees: Int = objects.count

            let totalStampees = String(stampees)
            self.stampeesCollectedLabel.text = totalStampees
            print(objects.count)
        }

    }


    // Do any additional setup after loading the view.
}

您想过滤扫描数组中的元素。对于每种代码类型,调用

// '[=10=]' is your PFObject. Replace 'name' with whatever `PFObject` property 
// represents the object's type
let nailSalons = objects.filter { [=10=].name == "Nail Salon" }

然后您可以使用这个过滤后的数组来计算您的计数。

请注意 filter { [=12=]... } 语法是 shorthand for

objects.filter { (object) throws -> Bool) in
    return object.name == "Nail Salon"
}

如果您的条件比简单的 one-line 表达式更复杂,则需要使用完整版。请注意,在简短版本中,隐含 return