我有一个案例,我应该通过UIViewController
. 我设计了我的数据库模型(实体和属性)。我正在通过UIViewController
. 我应该didFinishLaunchingwithOptions
在 appDelegate.m 的方法中添加什么?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch
return YES;
}
对于TUTViewController
(我自己的视图控制器 - UIViewController
),我使用下面的代码插入对象。
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];
NSEntityDescription *entity = [[self.fetchedResultsController fetchRequest] entity];
NSManagedObject *newManagedObject = [NSEntityDescription insertNewObjectForEntityForName:[entity name] inManagedObjectContext:context];
NSString *stripped1 = [response stringByReplacingOccurrencesOfString:@"\r" withString:@""];
NSMutableArray *rows = [NSMutableArray arrayWithArray:[stripped1 componentsSeparatedByString:@"\n"]];
NSMutableArray *contentArray = [NSMutableArray arrayWithCapacity:[rows count]];
NSMutableArray *contentArray1 = [NSMutableArray arrayWithCapacity:[rows count]];
NSArray *components;
NSLog(@"count:%d",[rows count]);
for (int i=0;i<[rows count]; i++) {
if(i == 0 || [[rows objectAtIndex:i] isEqualToString:@""]){
continue;
}
components = [[rows objectAtIndex:i] componentsSeparatedByString:@","];
id x = [components objectAtIndex:0] ;
id y = [components objectAtIndex:1];
id z = [components objectAtIndex:2];
[contentArray addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:x,@"X",y,@"Y", nil]];
[contentArray1 addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:x,@"X",z,@"Y", nil]];
[newManagedObject setValue:[x] forKey:@"timeStamp"];
[newManagedObject setValue:[y] forKey:@"beat"];
[newManagedObject setValue:[z] forKey:@"rate"];
// Save the context.
NSError *error = nil;
if (![context save:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
NSLog(@"Contents of Uterus Contraction: %@",contentArray);
NSLog(@"Contents of Heart Beat: %@",contentArray1);
}
}
}
有什么我想念的吗?我以错误结束:
由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“+entityForName:找不到实体名称“FetalData”的 NSManagedObjectModel