无法从对象创建BOOL [英] Cannot create BOOL from object

查看:247
本文介绍了无法从对象创建BOOL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循的指导可可编程的mac os x,第4版。在第32章我搞砸了代码,我没有备份它,所以我不得不从大书呆子牧场下载解决方案。 >
该项目是关于核心数据relashionships,有一个类Employee和类部门。

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:

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:

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: p>

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:

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:

我还使用一些数组控制器将核心数据值绑定到一些插座。

完整的项目可以找到这里。,第32章(与我的相同)在下载解决方案。
如果您需要更多代码来了解此错误,请告诉我:

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:我使用从解决方案下载的代码,它是相同的,但它不工作,也许是因为我有一个更高版本的xcode。

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.

推荐答案

看起来像一个绑定问题。您可能具有与无法转换为BOOL的属性链接的已启用或隐藏绑定(它接受BOOL)。

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.

这篇关于无法从对象创建BOOL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆