How to make base model
HarunBahcel opened this issue · comments
Problem is I have one main model. I have two sub-models
@interface UserModel : JSONModel
@property (nonatomic) NSInteger Id;
@property (nonatomic) NSInteger SponsorId;
@end
@interface FinanceModel : JSONModel
@property (nonatomic) NSInteger Id;
@property (nonatomic) NSInteger Money;
@end
@interface BaseModel : JSONModel
@property KullaniciModel *Result;
@property NSInteger Status;
@property NSString *ErrorMessage;
@end
@interface BaseModel : JSONModel
@property FinanceModel *Result;
@property NSInteger Status;
@property NSString *ErrorMessage;
@end
How do I get a Single Base Model?
for example
@interface BaseModel : JSONModel
@property JsonModel <BaseClass> *Result;
@property NSInteger Status;
@property NSString *ErrorMessage;
@end
UserModel Json
{
"Result": {
"Id": 12312312312,
"SponsorId": 0,
},
"Status": "1",
"ErrorMessage": ""
}
FinanceModel Json
{
"Result": {
"Id": 12312312312,
"Money": 110.00,
},
"Status": "1",
"ErrorMessage": ""
}
How do I import a User and Finance model in a Base model
These are just examples. I have 50 sub-models and I need to create a Base Model for all of them.
Help Me?
Judging from your data, I might try something like:
@interface BaseModel : JSONModel
@property NSString *Status;
@property NSString *ErrorMessage;
@end
@interface UserModel : BaseModel
@property UserSubModel *Result;
@end
@interface UserSubModel : JSONModel
@property NSInteger *Id;
@property NSInteger *SponsorId;
@end
@interface FinanceModel : BaseModel
@property FinanceSubModel *Result;
@end
@interface FinanceSubModel : JSONModel
@property NSInteger *Id;
@property NSInteger *Money;
@end
It may not be ideal because BaseModel
doesn't make it clear that a Result
field will always exist, but since Result
can take two different types this is the only way I know to do this with JSONModel. Often when working with de-serialization libraries (JSONModel, GSON, Newtonsoft, etc) you need consistency in your JSON or it leads to complex workflows and hacks.