iPhone-保存核心数据会在应用启动时导致多个相同的对象

|| 好的,伙计们,我正在努力弄清楚这个问题,但我现在很困难。因此,此应用程序具有一个XML解析器,该解析器可以捕获所有xml,对其进行解析并将所有数据存储在Core Data中。这一切都很好。但是,我试图保存核心数据并在下次运行时调用它,除非我这样做时,解析器再次运行,并且相同的项目再次在uitableview中聚合。我知道这是因为在applicationDidFinishLaunchingWithOptions中,每次运行应用程序时,我都会调用[parser getAllConferences],但是我不确定如何仅在核心数据为空时运行此程序。希望大家能对此事有所了解:)欢迎任何意见和建议,如有需要,请告诉我!
     - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {


        SHPEXmlParser *parser = [SHPEXmlParser alloc];

        [parser initWithManagedObjectContext:[self managedObjectContext]];

        [parser getAllConferences];
        [parser release];

        [self.viewController initWithContext:[self managedObjectContext]];

        // Override point for customization after application launch.
        self.window.rootViewController = self.viewController;
        [self.window makeKeyAndVisible];
        return YES;
    }

- (void)applicationWillTerminate:(UIApplication *)application
{
    [self saveContext];
}

- (void)saveContext
{
    NSError *error = nil;
    if (managedObjectContext != nil)
    {
        if ([managedObjectContext hasChanges] && ![managedObjectContext save:&error])
        {
            /*
             Replace this implementation with code to handle the error appropriately.

             abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. If it is not possible to recover from the error, display an alert panel that instructs the user to quit the application by pressing the Home button.
             */
            NSLog(@\"Unresolved error %@, %@\", error, [error userInfo]);
            abort();
        } 
    }
}
    
已邀请:
        怎么了?
if (NO == [[NSFileManager defaultManager] fileExistsAtPath:@\"put your path to sqlite file here\"]) {
    //parse stuff and load data into store
}
要么
NSFetchRequest *conferencesRequest = [NSFetchRequest fetchRequestForEntityWithName:@\"conferences\" inManagedObjectContext:context];
NSArray *conferences = [self.managedObjectContext executeFetchRequest:conferencesRequest];
if (conferences.count == 0) {
       //parse stuff and load data into store
}
请注意,上面的代码可能不会编译,但是希望可以说明该方法。     
        您可以将最后一个项目与要从解析器中获取的项目进行比较。将解析器中的数据保留在NSMutableArray中,然后执行此检查以查看具有相同项目的索引,并停止检查聚合数据。     

要回复问题请先登录注册