我有一个方法是无效的,但我必须计算它的条目数。计数NSFetchRequest的条目数
那么有什么办法可以做到吗?
我试图实现它,但它不工作。
它给我一个Nsfetch数的错误。
返回声明为空。
testcase1
{
//startdate and end date are same and both are 1 day before
NSTimeInterval secondsPerday=24*60*60;
NSDate *startdate = [[NSDate alloc]initWithTimeIntervalSinceNow:-secondsPerday];
NSDate *endate = [[NSDate alloc]initWithTimeIntervalSinceNow:-secondsPerday];
TravelerAppDelegate *delegate =[[UIApplication sharedApplication]delegate];
[delegate getWeatherforCity:@"#" state:@"#" country:@"#" startDate:startdate endDate:endate];
NSManagedObjectContext *allone=[delegate managedObjectContext];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Weather" inManagedObjectContext:allone];
//WeatherXMLParser *delegate = [[WeatherXMLParser alloc] initWithCity:@"#" state:@"#" country:@"#"];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:[NSEntityDescription entityForName:@"Weather" inManagedObjectContext:allone]];
[request setIncludesSubentities:NO];
NSError *err;
NSUInteger count = [allone countForFetchRequest:request error:&err];
if(count == NSNotFound) {
//Handle error
}
[request release];
return count;
}
如果代码“给你一个错误“,在你的问题中包含这个错误是非常有用的。 – jrturton