问题描述
我做了很多查询,在网站上搜索过,之前已经问过这个问题,我没有找到好的答案!
I have did a lot of querys, searched in websites , And already asked this question before and i didn't found a good answer!
我的 Parse 后端如下所示:
I have Parse backend looks like this:
在我的视图控制器中,我只想为每个发件人显示 Last createdAt我想为发件人获取最后一个对象的所有行:.
In my view controller I just want to show Last createdAt for each senderi want to get all the row of last object for sender:.
所以我们应该忽略name1:Hello"和name2:Really when was.."因为这些旧行我们已经有了新对象.
so we should ignore "name1: Hello" and "name2: Really when was.." because this old rows we already got new objects.
我希望每个发件人的结果取决于 createdAt
I want one result for each sender depends on createdAt
那么我可以通过查询获得帮助吗?或者我们怎么做?
so can I get help with query to do this? or how can we do that?
let query = PFQuery(className: "test")
query.whereKey("receivers", equalTo: PFUser.currentUser()!.username!)
query.orderByDescending("createdAt")
query.findObjectsInBackgroundWithBlock {
(objects, error) -> Void in
if error == nil {
// now what? I've done everything i could none worked fine
我希望我能得到帮助,所以如果可以,请帮助我.
I hope if i'll get a help to do that, So please help me if you could.
推荐答案
你可以只添加一个 limit
到查询中.. 见解析文档..
you can just add a limit
to the query.. see parse docs..
let query = PFQuery(className: "test")
query.whereKey("receivers", equalTo: PFUser.currentUser()!.username!)
query.orderByDescending("createdAt")
query.limit = 1
query.findObjectsInBackgroundWithBlock {
(objects, error) -> Void in
if error == nil {
这篇关于快速解析查询获取最后一个 createdAt 对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!