-1
- Core Data中是否存在存儲過程概念?如果是這樣, 請分享一些示例項目鏈接
我曾經看到記錄是從實體使用下面的代碼獲取。爲什麼不使用SQL查詢?存儲過程概念是否存在於核心數據中?
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; [fetchRequest setEntity: [NSEntityDescription entityForName: @"ServiceTypes" inManagedObjectContext: context]]; [fetchRequest setPredicate: [NSPredicate predicateWithFormat: @"serviceTypeID == %@", arrData[0]]]; NSError *error = nil; NSArray *fetchResult = [context executeFetchRequest: fetchRequest error:&error]; if (error) { NSLog(@"Unable to execute fetch request."); NSLog(@"%@, %@", error, error.localizedDescription); } else { if (fetchResult.count > 0) { ServiceTypes object = (ServiceTypes)[fetchResult objectAtIndex: 0]; if (!boolCkl) { [object setValue:arrData[1] forKey:@"code"]; NSLog(@"Service Type Data Updated"); } else { [context deleteObject: object]; NSLog(@"Service Type Data Deleted"); } } else { ServiceTypes *object = [NSEntityDescription insertNewObjectForEntityForName: @"ServiceTypes" inManagedObjectContext: context]; [object setValue: arrData[0] forKey: @"serviceTypeID"]; [object setValue: arrData[1] forKey: @"code"]; } }
對Core Data進行一些基本的閱讀是件好事。它不是傳統的SQL數據庫。 –