2017-05-25 80 views
0

我有一個與我的服務器解析問題,特別是我添加的變量。它不允許我添加它。該錯誤信息是「錯誤的接收器類型‘布爾’(又名‘布爾’)」糟糕的接收器類型「布爾」

這裏是我的代碼:

@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];

任何幫助欣賞。

+0

@property(nonatomic,assign)BOOL support_long_messages;嘗試這個。 – phani

+0

不,在我的功能不起作用,問題不是一個變量,它是一個參數,不在副本中分配。 – Steven

回答

0

只需

_support_long_messages = support_long_messages; 

BOOL是值類型,分配已經創建了一個副本。 顯式複製僅適用於引用類型(對象)。