Objective-C:设置布尔值的问题?

时间:2014-09-02 16:08:29

标签: ios objective-c iphone

考虑这个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

enter image description here

这不是设置boolean值的正确方法吗?

3 个答案:

答案 0 :(得分:3)

应该{​​{1}}不是@property (nonatomic, assign) BOOL debit;

答案 1 :(得分:1)

你写了BOOL *debit;,意思是指向BOOL

的指针

将其更改为BOOL debit;

答案 2 :(得分:1)

@property (nonatomic, assign) BOOL *debit;不应该有星号(*)