0
我正在使用nsxml解析器,并且我遇到了一些问题。我使用nsxml解析器来解析日期。我想仅获取2天的信息.not所有4个来自谷歌天气api.How我可以做到吗?如何匹配解析器的nsxml日期并获取所需的日期
NSMutableArray *array=[NSMutableArray arrayWithObjects:startDate,endDate,Nil];
for (NSDate *date in array)
{
if([date isEqualToDate:dd])
{
NSManagedObject *allnew = Nil;
NSManagedObjectContext *allone=[self managedObjectContext];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Weather" inManagedObjectContext:allone];
NSLog(@" The NEW ENTITY IS ALLOCATED AS entity is %@",entity);
WeatherXMLParser *delegate = [[WeatherXMLParser alloc] initWithCity:city state:state country:country];
NSXMLParser *locationParser = [[NSXMLParser alloc] initWithContentsOfURL:delegate.url];
[locationParser setDelegate:delegate];
[locationParser setShouldResolveExternalEntities:YES];
[locationParser parse];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entity];
predicate = [NSPredicate predicateWithFormat:
@"city == %@ and state == %@ and country == %@ and date==%@ and date==%@", city, state, country,startDate,endDate];
[request setPredicate:predicate];
NSError *err;
NSUInteger count = [allone countForFetchRequest:request error:&err];
NSLog(@" minimum salary is %@",predicate);
// If a predicate was passed, pass it to the query
if(predicate !=NULL){
[self deleteobject];
}
Weather *weather = (Weather *)[NSEntityDescription insertNewObjectForEntityForName:@"Weather"
inManagedObjectContext:self.managedObjectContext];
weather.date = [fields objectForKey:@"date"];
weather.high =[fields objectForKey:@"high"];
weather.low = [fields objectForKey:@"low"];
weather.city =[fields objectForKey:@"city"];
weather.state =[fields objectForKey:@"state"];
weather.country =[fields objectForKey:@"country"];
NSString*icon=[fields objectForKey:@"icon"];
NSString *all=[icon lastPathComponent];
weather.condition = all;
[self saveContext];
}
我将文件从解析器存储到nsdictionary中。 – iphone
我指的是您正在解析的实际XML格式。无论如何,创建一个标志/计数器,而不是解析超过您的需要应该解决您的问题。 –
你能告诉我虚拟代码吗...我无法在网上找到任何例子。我在客观的c中非常新。 – iphone