我有一個方法是無效的,但我必須計算它的條目數。計數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