I am following the guide cocoa programming for mac os x, 4th edition.In the 32th chapter I messed up the code, and I didn’t backup it, so I had to download the solutions from big nerd ranch.
The project is about core data relashionships, there is a class Employee and a class Department.
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
Department.m :
#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 %@",
[self deptName], [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
I have those core data relashionships and entities:


I also use some array controllers to bind the core data values to some outlets.
The full project can be found here., 32th chapter (it’s identical to mine) in “download solutions”.
Tell me if you need more code to understand this error:
2012-10-31 15:27:43.977 Departments[1229:303] Cannot create BOOL from object (
) of class _NSControllerArrayProxy
2012-10-31 15:27:43.989 Departments[1229:303] Cannot create BOOL from object (
) of class _NSControllerArrayProxy
Seems like posting a whole project is not recommended, but I could do so if you say it’s ok.
PS: I’ using the code downloaded from solutions, it’s the same but it doesn’t work, maybe because I have a higher version of xcode.
Looks like a bindings issue. You probably have an “enabled” or “hidden” binding (which takes a BOOL) linked up with a property that cannot be converted to BOOL.