核心数据和10 000个audio文件

我有一个实体“Word”,它有两个属性 – inputSound和outputSound,它们都很less,大约有10KB的audio文件,但是在我的SQL数据库中会有4000个实体。

首先,我尝试将它们作为二进制数据存储在我的SQL中,并且使其工作非常缓慢。 所以,然后我发现了一个选项“存储在外部logging文件”,我想问,如果这将帮助我,或者我应该更好地存储url到我的实体属性的audio文件?

如果第一个更好,我应该如何将第一次启动时从Bundle移动到文档目录?

现在,我只是应付一个SQL(它在我的应用程序的开发人员的一部分,我已经预先填充),但我应该如何做这么多的文件?我可以这样做在后台以某种方式使我的第一次发射更快,更用户友好?

这是我现在做的

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator { if (__persistentStoreCoordinator != nil) return __persistentStoreCoordinator; NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil]; NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject]; NSString *defaultStore = [documentsDirectory stringByAppendingPathComponent:@"Easy10.sqlite"]; NSString *sqliteInBundle = [[[NSBundle mainBundle] pathForResource:@"Easy10" ofType:@"sqlite"]stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"Easy10.sqlite"]; NSError *error =nil; NSFileManager *fileManager = [NSFileManager defaultManager]; if (![fileManager fileExistsAtPath:defaultStore]) [fileManager copyItemAtPath:sqliteInBundle toPath:defaultStore error:&error]; __persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]]; [__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error]; return __persistentStoreCoordinator; 

}

对于二进制文件(尤其是大文件,虽然你的“许多”也可以应用),推荐的方法似乎是使用核心数据来存储元数据, 包括实际二进制本身的文件path 。 因此,您应该将这些东西存储在应用程序的沙箱中(也就是说,在“文档”目录中可能是您​​创build的子目录)。 然后你可以使用[NSData dataWithContentsOfFilePath]或者类似的方法在你想要播放的时候获取字节,但是你的Core Data抓取并不会因为试图铲掉那些字节而变慢。

绝对要看WWDCvideo优化核心数据。 如何使用仪器和附加的“SQL Debug Timing”开关的好例子,以确保你正在优化…实际上得到了优化。 🙂