サーバーからのデータ
{
"type": "reward",
"stamp_pos": "1",
"reward_id": "350",
"reward_title": "dfddffd",
"reward_cost": "1",
"reward_cost_text": "Stamp Reward",
"reward_tnc": "12pm between Monday - Thursday.",
"member_reward_tracker_id": "1180",
"redeem_now": "1",
"redeemed": "0",
"active": "1",
"redeemed_date": "0000-00-00 00:00:00",
"reward_featured_image": "rs/img/someimage"
},
私がやろうとしていることは
私のモデル.h
typedef NS_ENUM(NSInteger, CardType) {
CardTypeStampAvailable = 1,
CardTypeStampRedeemed,
CardTypeRewardAvailable,
CardTypeRewardRedeemNow,
CardTypeRewardRedeemed,
};
@interface ModelCardReward : MTLModel <MTLJSONSerializing>
@property(nonatomic) CardType myCardType;
@property(nonatomic, strong) NSString *rewardTitle
@property(nonatomic, strong) NSString *rewardCostText;
@end
私のモデル.m
@implementation ModelCard
+ (NSDictionary *)JSONKeyPathsByPropertyKey {
return @{
@"rewardTitle" : @"reward_title",
@"rewardCostText" : @"reward_cost",
};
}
myCardType
辞書パラメーターに基づいて、変数に NS_ENUM 値を持たせたいと考えています。
あれは
if ([json[@"type"] isEqualToString:reward] && [json[@"redeem_now"] isEqualToString:@"1"]) {
myCardType = CardTypeRewardAvailable;
}
どんな助けでも素晴らしいでしょう。