1

I have an array that stores models:

@property (nonatomic, strong) NSMutableArray *models;

and other properties of type "Model",like:

@property (nonatomic, strong) Model *mainModel;
@property (nonatomic, strong) Model *adModel;
@property (nonatomic, strong) Model *tradeModel;
@property (nonatomic, strong) Model *tradeOpenModel;

I want to assign every element of models to property, how can I do this by runtime instead of self.mainModel = models[0];

9
  • how a model is identified as main,ad,trade,tradeopen model? Commented Oct 30, 2017 at 7:28
  • 1
    Why you don't want to use self.mainModel = models[0] ? Commented Oct 30, 2017 at 7:33
  • just an example, I want to get the model by property instead of models[0]. Commented Oct 30, 2017 at 7:35
  • 1
    Did you mean [models objectAtIndex:0]? You should explain you question more clearly. Commented Oct 30, 2017 at 7:46
  • If you are able to differentiate model through a property then you don't need these extra properties. Just filter your array whenever you need a specific model by that property. Commented Oct 30, 2017 at 7:54

1 Answer 1

3

Instead of NSMutableArray use a custom model (lets say allModelList) that will contain the other four models i.e mainModel,adModel,tradeModel,tradeOpenModel as properties. So while parsing you can set these properties and then easily access by

allModelList.mainModel
allModelList.adModel
allModelList.tradeModel
allModelList.tradeOpenModel

Hope it helps you.

Sign up to request clarification or add additional context in comments.

1 Comment

Let me know if some other help is required :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.