【发布时间】:2017-10-25 20:49:59
【问题描述】:
我在解析服务器时遇到问题,特别是我添加的变量。它不允许我添加它。错误消息是“错误的接收器类型“布尔”(又名“布尔”)”
这是我的代码:
@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 副本] ;
任何帮助表示感谢。
【问题讨论】:
-
@property (nonatomic, assign) BOOL support_long_messages;试试这个。
-
不,在我的函数中不起作用,问题不是变量,而是副本中没有赋值的参数。
标签: objective-c json boolean