I am working on coredata based and XML parsing[RSS Feed] based project. I have to check that if attribute value is available or not in coredata ?
For example :-
I have 3 attribute in my datamodel. name,websitename and feedurl. Now i have to parsing the url with user's input. but at the time of parsing i want to check that if URLNAME is available in coredata or not. If available then parsing will done without inserting into coredata and if URL is not in coredata then it will be inserted into coredata.
Here is my try from where i am able to insert the url in core data. but with this method same url is also enters in coredata.
- (void)feedParserDidFinish:(MWFeedParser *)parser {
[HUD hide:YES];
//**Coredata inserting value**//
NSManagedObjectContext *context = [self managedObjectContext];
// Create a new managed object
NSManagedObject *newDevice = [NSEntityDescription insertNewObjectForEntityForName:@"I" inManagedObjectContext:context];
[newDevice setValue:self.Name forKey:@"name"];
[newDevice setValue:self.WebsiteName forKey:@"websitename"];
[newDevice setValue:self.Feedlink forKey:@"feedurl"];
NSError *error = nil;
// Save the object to persistent store
if (![context save:&error]) {
NSLog(@"Can't Save! %@ %@", error, [error localizedDescription]);
}
//**Parsing url**//
NSLog(@"Finished Parsing%@", (parser.stopped ? @" (Stopped)" : @""));
NSArray* array =[parsedItems sortedArrayUsingDescriptors:
[NSArray arrayWithObject:[[NSSortDescriptor alloc] initWithKey:@"date"
ascending:NO]]];
NSMutableDictionary* dict = [NSMutableDictionary new];
[dict setObject:chanelInfo forKey:@"title"];
[dict setObject:array forKey:@"data"];
[sectionheaders addObject:dict];
NSLog(@"SectionHeader Count:%ld",(long)sectionheaders.count);
[self updateTableWithParsedItems];
}