2017-05-25 5 views
0

Ich habe ein Problem mit dem Parsen mit meinem Server, vor allem die Variable, die ich hinzufüge. es lässt mich nicht hinzufügen. die Fehlermeldung "Bad Empfängertyp "Bool"(aka "Bool")"Bad Empfänger Typ "Bool"

hier ist mein Code:

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

so dass der Fehler, die ich von _support_long_messages erhalten, wenn ich zuweisen möchten:

_support_long_messages = [support_long_messages Kopie];

jede Hilfe zu schätzen wissen.

+0

@property (nicht atomisch, zuweisen) BOOL support_long_messages; Versuche dies. – phani

+0

Nein, funktioniert nicht in meiner Funktion, das Problem ist keine Variable, es ist ein Parameter, der nicht in der Kopie zugeordnet wird. – Steven

Antwort

0

einfach

_support_long_messages = support_long_messages; 

BOOL ist ein Werttyp, Zuordnung erzeugt bereits eine Kopie. Explizite Kopie ist nur für Referenztypen (Objekte) erforderlich.

Verwandte Themen