Core data [\uu NSCFSet entity]:将新nsmanegedobject插入到多对多关系时无法识别的选择器

Core data [\uu NSCFSet entity]:将新nsmanegedobject插入到多对多关系时无法识别的选择器,core-data,unrecognized-selector,Core Data,Unrecognized Selector,我正在将杂务对象的新实例添加到帐户实例。它们都是NSManagedObject,从Account到Chore的关系是“一对多”的关系 account实例在运行时是有效的,因为我可以向它插入其他对象,这些对象遵循与chore相同的关系规则(1到多),并且chore也有效,因为在调试器中account对象和newChore都有有效的内存地址。唯一的问题是错误中给出的地址,因为0x6d85cb0与此错误报告时newChore和account where的地址不同。0x06b74a70表示newChor

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

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

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

这是代码行[account addChoresObject:newChore];生成以下错误。 2012-05-31 10:19:05.440分配[61436:fb03]-[\uu NSCFSet entity]:发送到实例0x6d85cb0的无法识别的选择器 2012-05-31 10:19:05.441分配[61436:fb03]*由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:'-[\u NSCFSet entity]:未识别的选择器发送到实例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类的接口,由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
在我看来,选择器似乎被发送到了错误的地址。 我尝试使用Clean来清除潜在的错误构建文件。
在此之前,我很难正确生成文件,因为生成的文件是用应用程序的名称调用的,而不是用类的名称调用的,并且在尝试自动生成iboutlets和ibaction时,有些源文件会使xcode崩溃。我想知道是否有其他人有xcode的问题,如果重新安装它可能会解决我的问题

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


NSLog
account变量,然后再添加杂务并查看其中的内容。也许它是未定义的,您必须确保它引用了您想要的内容。

这是nslog中的内容
2012-06-01 00:45:31.588分配[76515:fb03]帐户:(实体:帐户;id:0x6be0670;数据:{余额=22;生日=“2012-06-01 04:45:08+0000”;家务=零;礼物=();姓名=测试帐户;操作=(“0x6be0840”);照片=零;})
——琐事是零,就像一对一的关系。因此,我将addchoresobject更改为account.chore=newChore;这确实有效。因此,这让我猜测一下,并将模型文件重命名为modelfile.old,创建一个新的1,将我的entety复制到新的1,并从模拟器中删除该应用程序以获得新的开始。它成功了。是的,这不是代码问题或运行时问题,因为我的模型文件已损坏。刚重新安装应用程序,我就知道storecoordinator是空的。谢谢你,有收获了。
@interface Chore : NSManagedObject

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

@end