gpt4 book ai didi

ios - '+ entityForName:nil不是搜索实体名称的合法NSManagedObjectContext参数

转载 作者:行者123 更新时间:2023-12-01 17:41:24 25 4
gpt4 key购买 nike

我正在尝试将记录保存在表中。
我阅读了StackOverflow中的所有问题和答案,但无法解决问题。
当我尝试保存数据时,出现错误:

2013-08-31 22:25:37.321 OnTheRoadV2[26581:11603] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+entityForName: nil is not a legal NSManagedObjectContext parameter searching for entity name 'Trip''
*** First throw call stack:
(0x18e7012 0x1427e7e 0x743e7 0xba402 0x41db 0x143b705 0x372920 0x3728b8 0x433671 0x433bcf 0x432d38 0x3a233f 0x3a2552 0x3803aa 0x371cf8 0x2404df9 0x2404ad0 0x185cbf5 0x185c962 0x188dbb6 0x188cf44 0x188ce1b 0x24037e3 0x2403668 0x36f65c 0x29ed 0x2915)
libc++abi.dylib: terminate called throwing an exception

我的代码:
- (IBAction)start:(id)sender {
NSManagedObjectContext *context = [self managedObjectContext];

// Create a new managed object
NSManagedObject *newTrip = [NSEntityDescription insertNewObjectForEntityForName:@"Trip" inManagedObjectContext:context];
[newTrip setValue:self.name.text forKey:@"name"];

NSError *error = nil;
// Save the object to persistent store
if (![context save:&error]) {
NSLog(@"Can't Save! %@ %@", error, [error localizedDescription]);
}
_status.text = @"Trip started!";


}

- (NSManagedObjectContext *)managedObjectContext {
NSManagedObjectContext *context = nil;
id delegate = [[UIApplication sharedApplication] delegate];
if ([delegate performSelector:@selector(managedObjectContext)]) {
context = [delegate managedObjectContext];
}
return context;
}

最佳答案

如果您不熟悉核心数据,请使用魔术记录。
它易于集成:
这是教程:
http://ablfx.com/blog/article/2

关于ios - '+ entityForName:nil不是搜索实体名称的合法NSManagedObjectContext参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18554385/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com