0
我想設置如果rss feedurl在coredata中可用,那麼只有解析完成否則它將存儲在coredata中。 我已經嘗試實現方法這個問題
IOS Coredata check if attribute is exist or notios coredata如何檢查rssfeed url是否存在於coredata中
這裏的基準是我的嘗試:
- (void)feedParserDidFinish:(MWFeedParser *)parser {
[HUD hide:YES];
//**Coredata inserting value**//
NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"maindata"];
NSFetchRequest *fetchrequestforside=[NSFetchRequest fetchRequestWithEntityName:@"anotherdata"];
fetchRequest.predicate = [NSPredicate predicateWithFormat:@"urloffeed = %@", self.linkfeed];
fetchrequestforside.predicate=[NSPredicate predicateWithFormat:@"furloffeed = %@", self.linkfeed];
NSManagedObjectContext *context = [self managedObjectContext];
if ([[context executeFetchRequest:fetchRequest error:NULL] count] == 0) {
// Create a new managed object
NSManagedObject *newDevice = [NSEntityDescription insertNewObjectForEntityForName:@"maindata" inManagedObjectContext:context];
[newDevice setValue:self.Name forKey:@"urlname"];
[newDevice setValue:self.WebsiteName forKey:@"websitename"];
[newDevice setValue:self.Feedlink forKey:@"urloffeed"];
NSError *error = nil;
// Save the object to persistent store
if (![context save:&error]) {
NSLog(@"Can't Save! %@ %@", error, [error localizedDescription]);
}
}
if ([[context executeFetchRequest:fetchrequestforside error:NULL] count] == 0) {
// Create a new managed object
NSManagedObject *newDevice1 = [NSEntityDescription insertNewObjectForEntityForName:@"anotherdata" inManagedObjectContext:context];
if (self.urlname) {
[newDevice1 setValue:self.Name forKey:@"urlname"];
}
if (self.WebsiteName) {
[newDevice1 setValue:self.WebsiteName forKey:@"websitename"];
}
if (self.urloffeed) {
[newDevice1 setValue:self.Feedlink forKey:@"urloffeed"];
}
NSError *error = nil;
// Save the object to persistent store
if (![context save:&error]) {
NSLog(@"Can't Save! %@ %@", error, [error localizedDescription]);
}
}
注: - 我要救網址兩個實體。
使用搜索查詢在相應欄中的URL值。 – rptwsthi
唯一和最好的方法:你應該做一個謂詞,並在插入 – Mohamad
之前檢查你的數據庫上的這個網址,你可以請詳細解釋我是新來的ios所以,我不知道如何設置檢查網址在coredata條件? –