考虑这个json
{
"amount": "60.81",
"category": "Utilities",
"debit": true,
"name": "Comcast",
"date": "Sat, 02 Aug 2014 14:36:46 -0000",
"uuid": "112c43eb-6e5e-4b4d-9079-6d896fa11b01"
}
我有一个TransactionModel
类看起来像
TransactionModel.h
@interface TransactionModel : NSObject
@property (nonatomic, strong) NSString *uuid;
@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) NSString *amount;
@property (nonatomic, strong) NSString *category;
@property (nonatomic, assign) BOOL *debit;
@property (nonatomic, strong) NSString *date;
- (TransactionModel *) initWithDictionary: (NSDictionary *) dictionary;
@end
并在 TransactionalModel.m 中,我执行以下操作
@implementation TransactionModel
- (TransactionModel *)initWithDictionary:(NSDictionary *)dictionary {
TransactionModel *transactionModel = [[TransactionModel alloc] init];
transactionModel.uuid = [dictionary valueForKey:@"uuid"];
transactionModel.name = [dictionary valueForKey:@"name"];
transactionModel.amount = [dictionary valueForKey:@"amount"];
transactionModel.debit = [[dictionary valueForKey:@"debit"] boolValue];
transactionModel.category = [dictionary valueForKey:@"category"];
transactionModel.date = [dictionary valueForKey:@"date"];
return transactionModel;
}
@end
我正在使用AppCode
并在线警告
transactionModel.debit = [[dictionary valueForKey:@"debit"] boolValue];
as
Taking pointer from integer without a cast
这不是设置boolean
值的正确方法吗?
答案 0 :(得分:3)
应该{{1}}不是@property (nonatomic, assign) BOOL debit;
。
答案 1 :(得分:1)
你写了BOOL *debit;
,意思是指向BOOL
将其更改为BOOL debit;
答案 2 :(得分:1)
@property (nonatomic, assign) BOOL *debit;
不应该有星号(*)