
该项目涉及核心数据关系,有一个班级员工和一个班级部门.
Employee.h:
#import <Foundation/Foundation.h>#import <CoreData/CoreData.h>@class Department;@interface Employee : NSManagedobject@property (nonatomic,copy) Nsstring * firstname;@property (nonatomic,copy) Nsstring * lastname;@property (nonatomic,retain) Department *department;@property (nonatomic,Readonly) Nsstring *fullname;@end
Employee.m:
#import "Employee.h"#import "Department.h"@implementation Employee@dynamic firstname;@dynamic lastname;@dynamic department;+ (NSSet *)keypathsForValuesAffectingFullname{ return [NSSet setWithObjects:@"firstname",@"lastname",nil];}- (Nsstring *)fullname{ Nsstring *first = [self firstname]; Nsstring *last = [self lastname]; if (!first) return last; if (!last) return first; return [Nsstring stringWithFormat:@"%@ %@",first,last];}@end Department.h:
#import <Foundation/Foundation.h>#import <CoreData/CoreData.h>@interface Department : NSManagedobject@property (nonatomic,retain) Nsstring * deptname;@property (nonatomic,retain) NSSet *employees;@property (nonatomic,retain) NSManagedobject *manager;@end@interface Department (CoreDataGeneratedAccessors)- (voID)addEmployeesObject:(NSManagedobject *)value;- (voID)removeEmployeesObject:(NSManagedobject *)value;- (voID)addEmployees:(NSSet *)values;- (voID)removeEmployees:(NSSet *)values;@end
部门:
#import "Department.h"#import "Employee.h"@implementation Department@dynamic deptname;@dynamic employees;@dynamic manager;- (voID)addEmployeesObject:(Employee *)value{ NSLog(@"Dept %@ adding employee %@",[self deptname],[value fullname]); NSSet *s = [NSSet setWithObject:value]; [self willChangeValueForKey:@"employees" withSetMutation:NSkeyvalueUnionSetMutation usingObjects:s]; [[self primitiveValueForKey:@"employees"] addobject:value]; [self dIDChangeValueForKey:@"employees" withSetMutation:NSkeyvalueUnionSetMutation usingObjects:s];}- (voID)removeEmployeesObject:(Employee *)value{ NSLog(@"Dept %@ removing employee %@",[value fullname]); Employee *manager = (Employee *)[self manager]; if (manager == value) { [self setManager:nil]; } NSSet *s = [NSSet setWithObject:value]; [self willChangeValueForKey:@"employees" withSetMutation:NSkeyvalueMinusSetMutation usingObjects:s]; [[self primitiveValueForKey:@"employees"] removeObject:value]; [self dIDChangeValueForKey:@"employees" withSetMutation:NSkeyvalueMinusSetMutation usingObjects:s];}@end 我有那些核心数据关系和实体:
我还使用一些阵列控制器将核心数据值绑定到某些出口.
整个项目可以在“下载解决方案”中找到here.,第32章(与我的相同).
如果您需要更多代码来了解此错误,请告诉我:
2012-10-31 15:27:43.977 Departments[1229:303] Cannot create BOol from object () of class _NSControllerArrayProxy2012-10-31 15:27:43.989 Departments[1229:303] Cannot create BOol from object () of class _NSControllerArrayProxy
似乎不建议发布整个项目,但如果你说它没问题,我可以这样做.
PS:我’使用从解决方案下载的代码,它是相同的但它不起作用,可能是因为我有更高版本的xcode.
解决方法 看起来像绑定问题.您可能有一个“启用”或“隐藏”绑定(带有BOol)与无法转换为BOol的属性相关联. 总结以上是内存溢出为你收集整理的objective-c – 无法从对象创建BOOL全部内容,希望文章能够帮你解决objective-c – 无法从对象创建BOOL所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)