首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >可以在Parse中创建特定对象的数组吗?

可以在Parse中创建特定对象的数组吗?
EN

Stack Overflow用户
提问于 2019-05-23 22:00:40
回答 1查看 49关注 0票数 0

我做了一个二维码扫描器应用程序,我已经手动将一些二维码放入解析中进行识别,任何扫描到的二维码都不会被识别。

唯一能区分他们的是他们的(信息),即“餐厅”,“美甲沙龙”等。

我后一种方式,能够记录多少次选择的QRCode已被扫描的整数,然后放在应用程序中的标签。

我可以(.count)用户保存和扫描的所有qrCodes,但似乎不知道如何在解析时将所有“美甲沙龙”放入它们自己的数组中,或者运行一个For循环来匹配我需要的那些。

代码语言:javascript
运行
复制
 // 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.
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-05-23 22:31:21

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

代码语言:javascript
运行
复制
// '$0' is your PFObject. Replace 'name' with whatever `PFObject` property 
// represents the object's type
let nailSalons = objects.filter { $0.name == "Nail Salon" }

然后,您可以使用这个经过过滤的数组来获取计数。

请注意,filter { $0... }语法是

代码语言:javascript
运行
复制
objects.filter { (object) throws -> Bool) in
    return object.name == "Nail Salon"
}

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56276964

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档