目标c解析,计算背景中的对象 [英] Objective c parse, count objects in background
本文介绍了目标c解析,计算背景中的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试获取在后台发现的查询数.因此,我使用countobjects方法获取数字,但是系统对此发出警告:正在主线程上执行长时间运行的操作."
I try to get the number of queries I found in background. So I use countobjects method to get the number, but system has warning about it "A long-running operation is being executed on the main thread."
PFQuery *query2=[PFQuery queryWithClassName:@"Comments"];
[query2 whereKey:@"Name" equalTo:globalName];
NSInteger CommentPoint=query2.countObjects;
所以我更改为这种方法,但是我无法在控制台中获得计数打印的数量.
so i change to this method, but i can't get numbers of count print in my console.
[query2 countObjectsInBackgroundWithBlock:^(int count, NSError *error)
{
if (!error) {
// The count request succeeded. Log the count
NSLog(@"Sean has played %d games", count);
} else {
// The request failed
}
}];
我的另一个问题是如何为全局NSinteger分配计数"?
My another question is how can I assign "count" to an Global NSinteger?
我尝试过
PFQuery *query=[PFQuery queryWithClassName:@"AllPost"];
[query whereKey:@"PostUser" equalTo:globalName];
NSLog(@"globalname %@",globalName);
[query countObjectsInBackgroundWithBlock:^(int count, NSError *error)
{
if (!error) {
self.objectCount = [NSNumber numberWithInt:count];
// The count request succeeded. Log the count
NSLog(@"Sean has played %d games", count);
} else {
NSLog(@"error");
}
}];
NSLog(@"objectCount %@",self.objectCount);
这是控制台打印出来的内容
this is what console print out
2015-07-02 19:17:16.721 ParseNews[12598:608067] globalname Sheng
2015-07-02 19:17:16.721 ParseNews[12598:608067] objectCount (null)
推荐答案
保存方法"的一种解决方案是创建一个全局NSNumber属性:
One solution for the 'how to save' could be to create a global NSNumber property:
@property (strong, nonatomic) NSNumber *objectCount;
然后,在块内:
self.objectCount = [NSNumber numberWithInt:count];
这篇关于目标c解析,计算背景中的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文