gpt4 book ai didi

core-data - [__NSCFSet实体] : unrecognized selector when insertin new nsmanegedobject to an to-many relation

转载 作者:行者123 更新时间:2023-12-04 16:50:41 24 4
gpt4 key购买 nike

我正在将 Chore 对象的新实例添加到 Account 实例。它们都是 NSManagedObjects,从 Account 到 Chore 的关系是“一对多”关系。

account 实例在运行时有效,因为我可以向它插入其他对象,这些对象遵循与 chore 相同的关系规则(1 到 many),并且 chore 也是有效的,因为在调试器中,account 对象和 newChore 有有效的内存地址。唯一的问题是错误中给出的地址,因为 0x6d85cb0 与 newChore 的地址不同,并且在出现此错误报告时帐户所在的地址。 0x06b74a70 用于 newChore 和 0x06d49700 用于帐户,所以我不知道 0x6d85cb0 指的是什么。

这是代码行“[account addChoresObject:newChore];”产生以下错误。

这是代码行 [account addChoresObject:newChore];产生以下错误。2012-05-31 10:19:05.440 分配 [61436:fb03] -[__NSCFSet 实体]:无法识别的选择器发送到实例 0x6d85cb02012-05-31 10:19:05.441 分配 [61436:fb03] * 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[__NSCFSet 实体]:无法识别的选择器发送到实例 0x6d85cb0”

这是产生错误的方法的代码。

-(void)addChore:(Chore *)newChore
{
[account addChoresObject:newChore];
NSError *error;
[managedObjectContext save:&error];
if (error != nil) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error Adding chore"
message:@"program not able to add new chore to account"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil, nil];
[alert show];
}
}

这是 Account 类的接口(interface),由 xcode 生成:

#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>

@class Chore, Gift, Goal, Operation;

@interface Account : NSManagedObject

@property (nonatomic, retain) NSNumber * balance;
@property (nonatomic, retain) NSDate * birthday;
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSData * photo;
@property (nonatomic, retain) NSSet *chores;
@property (nonatomic, retain) NSSet *gifts;
@property (nonatomic, retain) NSSet *goals;
@property (nonatomic, retain) NSSet *operations;
@end

@interface Account (CoreDataGeneratedAccessors)

- (void)addChoresObject:(Chore *)value;
- (void)removeChoresObject:(Chore *)value;
- (void)addChores:(NSSet *)values;
- (void)removeChores:(NSSet *)values;

- (void)addGiftsObject:(Gift *)value;
- (void)removeGiftsObject:(Gift *)value;
- (void)addGifts:(NSSet *)values;
- (void)removeGifts:(NSSet *)values;

- (void)addGoalsObject:(Goal *)value;
- (void)removeGoalsObject:(Goal *)value;
- (void)addGoals:(NSSet *)values;
- (void)removeGoals:(NSSet *)values;

- (void)addOperationsObject:(Operation *)value;
- (void)removeOperationsObject:(Operation *)value;
- (void)addOperations:(NSSet *)values;
- (void)removeOperations:(NSSet *)values;

@end

Chore 类是:

@interface Chore : NSManagedObject

@property (nonatomic, retain) NSString * interval;
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSString * reward;
@property (nonatomic, retain) Account *account;

@end

对我来说,选择器似乎发送到了错误的地址。我尝试使用 Clean 来删除潜在的错误构建文件。在此之前我很难正确生成文件,因为生成的文件是用应用程序的名称调用的,而不是用类的名称调用的,而且一些源文件也有问题,当 xcode 崩溃时尝试自动生成 iboutlets 和 ibaction。我想知道是否有其他人对 xcode 有问题,重新安装它是否可以解决我的问题。

最佳答案

我认为这与 addChore: 方法中的变量 account 未处于您期望的状态有关。

NSLog account 变量之前添加杂项,看看那里有什么。也许它是未定义的,你必须确保它指的是你想要的。

关于core-data - [__NSCFSet实体] : unrecognized selector when insertin new nsmanegedobject to an to-many relation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10838797/

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