我的应用程序目前有这个sqlite文件(让我们命名为v1)我想要做的是,当我激活IBAction时,它会自动删除当前文件(v1)并从webservice中检索值并存储在新文件中(v2)然后应用程序将使用新的sqlite文件(v2)
关于如何实施的任何想法?
我目前的代码在这里:
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
if (persistentStoreCoordinator != nil) {
return persistentStoreCoordinator;
}
NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"test.sqlite"]];
NSLog(@"%@",storeUrl);
NSError *error = nil;
persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:nil error:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
return persistentStoreCoordinator;
Run Code Online (Sandbox Code Playgroud)
}
只是想知道xCode是否能够在桌面上自动创建一个文件夹(如果它不存在)?
NSString *documentsDirectory = @"/Users/admin/Desktop/12Dec2012";
Run Code Online (Sandbox Code Playgroud)
假设文件夹"12Dec2012"未在桌面上创建,但我希望将.txt保存到文件夹"12Dec2012",xCode会自动创建该文件夹并将其存储在.txt文件中吗?
我的sqlite在其中一个实体中有项目,我希望根据它们的categoryID检索它们
例如,categoryID 1有7个项目,categoryID 2有5个项目,当我点击IBAction时,它会转到这个方法并根据我的global.clickedTag检索
但我无法检索值,任何想法为什么?
-(NSMutableArray*)fetchItem:array{
[self managedObjectContext];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"IItem" inManagedObjectContext:managedObjectContext];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
//filter here
NSPredicate * predicate = [NSPredicate predicateWithFormat:@"categoryID == %i",myGlobal.clickedTag];
[request setPredicate:predicate];
[request setEntity:entity];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"ID" ascending:YES];
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
[request setSortDescriptors:sortDescriptors];
[sortDescriptor release];
NSError *error;
NSMutableArray* mutableFetchCategory = [[managedObjectContext executeFetchRequest:request error:&error] mutableCopy];
if (!mutableFetchCategory) {
// Handle the error.
}
if ([mutableFetchCategory count] > 0)
{
for (NSManagedObject *info in mutableFetchCategory)
{
if …Run Code Online (Sandbox Code Playgroud)