使用swift在iOS应用程序中以编程方式计算Parse类中的行

使用swift在iOS应用程序中以编程方式计算Parse类中的行

本文介绍了如何使用swift在iOS应用程序中以编程方式计算Parse类中的行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我的iOS应用程序有一个解析后端。 我有一个名为quiz的解析类。如何读取Parse类中的行数,我必须在我的iOS应用程序中使用它?I have a parse back end for my iOS app.I have a parse class called "quiz". How can I read the number of rows in the Parse class, I have to use it in my iOS app?我使用以下代码,但xcode没有进入代码块。I am using the following code but xcode is not entering the code block.var cnt = 1var query = PFQuery(className:"quiz")query.findObjectsInBackgroundWithBlock {(objects: [PFObject]?, error: NSError?) -> Void inif error == nil{// The find succeeded.print("Successfully retrieved \(objects!.count) scores.")cnt = objects!.count}else{// Log details of the failureprint("Error: \(error!) \(error!.userInfo)")}}return cnt谢谢!推荐答案 快速回答 findObjectsInBackgroundWithBlock 受查询限制约束返回默认情况下最多100个对象。此限制可以增加,但仅限于最大值1000 。因此,您不能依赖 findObjects 然后计算结果。Quick AnswerfindObjectsInBackgroundWithBlock is constrained by the query limitation to return up to 100 objects by default. This limit can be increased, but only to a maximum of 1000. Because of this, you cannot rely on findObjects and then counting the results. Parse在文档中包含了一种计算类或特定对象总数的简单方法查询。Parse has included in the documentation a simple way to count the total number of objects for a class or particular query.var query = PFQuery(className:"GameScore")query.whereKey("playerName", equalTo:"Sean Plott")query.countObjectsInBackgroundWithBlock { (count: Int32, error: NSError?) -> Void in if error == nil { print("Sean has played \(count) games") }} Swift 3let query = PFQuery(className:"GameScore") query.whereKey("playerName", equalTo:"Sean Plott") query.countObjectsInBackground { (count, error) in if error == nil { print("Sean has played \(count) games") }} 详细说明 还应该注意到,由于计数操作的成本很高,Parse对它们施加了限制Detailed ExplanationIt should also be noted that due to how costly count operations are, Parse has placed limitations on them这种不准确性不是由1000个请求对象限制引起的。计数查询将尝试获取无论大小的记录总数,但由于操作可能需要很长时间才能完成,因此在该窗口期间数据库可能已更改,并且返回的计数值可能不会更长的是有效的。This inaccuracy is not due to the 1000 request object limit. The count query will try to get the total number of records regardless of size, but since the operation may take a large amount of time to complete, it is possible that the database has changed during that window and the count value that is returned may no longer be valid.处理计数的推荐方法是使用云代码中的保存触发器之前/之后基本上维护自己的索引。然而,这也是一个非理想的解决方案,因为保存挂钩可以在任何时候通过任意方式失败,并且(更糟糕的)postSave挂钩没有错误传播。除此之外,这里还有来自 Parse的Hector Ramos的另一句话。开发人员Google Group 。The recommended way to handle counts is to essentially maintain your own index using before/after save triggers in cloud code. However, this is also a non-ideal solution because save hooks can arbitrarily fail part way through and (worse) postSave hooks have no error propagation. To add on to this, here is another quote by Hector Ramos from the Parse Developers Google Group.最后,引用Parse Engineering博客文章:在Parse上构建可扩展的应用程序。And lastly, to quote the Parse Engineering Blog Post: Building Scalable Apps on Parse. 这篇关于如何使用swift在iOS应用程序中以编程方式计算Parse类中的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-28 03:42