gpt4 book ai didi

ios - NSManageObjectContext 保存 - 无法识别的选择器

转载 作者:行者123 更新时间:2023-11-29 03:12:58 25 4
gpt4 key购买 nike

尝试保存新的购物车商品,但收到此错误。

[CartItem save:]: unrecognized selector sent to instance 0xdd307f0
2014-02-25 12:24:45.206 Fashbowl[975:a0b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CartItem save:]: unrecognized selector sent to instance 0xdd307f0'




spAppDelegate *appDelegate = (spAppDelegate *)[[UIApplication sharedApplication] delegate];
NSManagedObjectContext *moc=[appDelegate managedObjectContext ];
moc = [[NSManagedObjectContext alloc] init] ;
[moc setPersistentStoreCoordinator:[appDelegate persistentStoreCoordinator ]];
NSManagedObjectContext *itemMo =[CartItem insertInManagedObjectContext:moc];
NSError *error;
NSString *cartId=[NSString getUniqueId]; //new cart

[itemMo setValue:cartId forKey:@"cart_id"];
// [itemMo setValue:[NSNumber numberWithDouble:[self.lblPrice.text doubleValue]] forKey:@"price"];
// [itemMo setValue:[NSNumber numberWithDouble:[self.lblComparePrice.text doubleValue]] forKey:@"compare_at_price"];


if (![itemMo save:&error]) {
NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]);
}

最佳答案

试试这个,

spAppDelegate *appDelegate = (spAppDelegate *)[[UIApplication sharedApplication] delegate];
NSManagedObjectContext *moc=[appDelegate managedObjectContext ];
if (!moc) {
moc = [[NSManagedObjectContext alloc] init] ;
[moc setPersistentStoreCoordinator:[appDelegate persistentStoreCoordinator ]];
}

CartItem *itemMo =[CartItem insertInManagedObjectContext:moc];
NSError *error;
NSString *cartId=[NSString getUniqueId]; //new cart

[itemMo setValue:cartId forKey:@"cart_id"];

if (![moc save:&error]) {
NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]);
}

关于ios - NSManageObjectContext 保存 - 无法识别的选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22004671/

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