糟糕的接收器类型" Bool"

时间:2017-05-25 09:04:43

标签: objective-c json boolean

我在使用服务器解析时遇到问题,特别是我添加的变量。它不允许我添加它。错误信息是"接收器类型错误" Bool"(又名" bool")"

这是我的代码:

@interface MessagingKeyServerResponse : NSObject <NSCopying>

@property (nonatomic, readonly) NSData *key;
@property (nonatomic, readonly) NSString *keyId;
@property (nonatomic, readonly) NSDate *validityStart;
@property (nonatomic, readonly) NSDate *validityEnd;
@property (nonatomic, readonly) BOOL support_long_messages;


@end



@interface MessagingKeyServerResponse ()


// added support_long_messages for parsing
-(instancetype)initWithKey:(NSData *)key keyId:(NSString *)keyId validityStart:(NSDate *)validityStart validityEnd:(NSDate *)validityEnd support_long_messages:(BOOL)support_long_messages;

@end

NS_ASSUME_NONNULL_END

@implementation MessagingKeyServerResponse

// steve note: added message long characters

-(instancetype)initWithKey:(NSData *)key keyId:(NSString *)keyId validityStart:(NSDate *)validityStart validityEnd:(NSDate *)validityEnd support_long_messages:(BOOL)support_long_messages
{
    if (!key) {
        [NSException raise:NSInvalidArgumentException format:@"No key"];
        return nil;
    }

    if (!keyId) {
        [NSException raise:NSInvalidArgumentException format:@"No key id"];
        return nil;
    }

    if (!validityStart) {
        [NSException raise:NSInvalidArgumentException format:@"No validity start"];
        return nil;
    }

    if (!validityEnd) {
        [NSException raise:NSInvalidArgumentException format:@"No validity end"];
        return nil;
    }


    if (!support_long_messages) {
        [NSException raise:NSInvalidArgumentException format:@"there is no support long Characters"];
        return nil;
    }



    if (!([validityStart compare:validityEnd] == NSOrderedAscending)) {
        [NSException raise:NSInvalidArgumentException format:@"Invalid validity range"];
        return nil;
    }



    self = [super init];

    if (self) {
        _key = [key copy];
        _keyId = [keyId copy];
        _validityStart = [validityStart copy];
        _validityEnd = [validityEnd copy];
        _support_long_messages = [support_long_messages copy] ;


        if (!_key || !_keyId || !_validityStart || !_validityEnd || !_support_long_messages) {
            return nil;
        }
    }

    return self;
}

所以当我想分配时,我从_support_long_messages收到错误:

_support_long_messages = [support_long_messages copy];

任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:0)

简单地

_support_long_messages = support_long_messages;

BOOL是值类型,赋值已创建副本。 只有引用类型(对象)才需要显式复制。