1

I have a basic question. While taking data for my table view in objective C. There are three diff fields image,title,description. So my is question whether I should make 3 diff NSArrays for them or just make a class of three variable and make a array of objects for better efficiency.

taking 3 arrays :

NSArray *image = [NSArray withObjects : @"one.jpg",@"two.jpg",nil];
NSArray *title = [NSArray withObjects : @"one",@"two",nil];
NSArray *description = [NSArray withObjects : @"number one",@"number two",nil];

or

User *dataOne = [User new]
dataOne.image= @"one.jpg";
dataOne.title = @"one";
dataOne.description =@"Number One";

User *dataTwo = [User new]
dataTwo.image= @"one.jpg";
dataTwo.title = @"one";
dataTwo.description =@"Number One";

NSArray *data = [NSArray dataOne,dataTwo, nil];

which is better approach ? please explain clearly. thank you

2 Answers 2

5

There is lots of advantages of Data Model.

  • Relationship
  • Data sharing
  • Data Integrity
  • Simplicity

Lets take a small example as you have taken three arrays of data, now if you want to pass single data to another view controller or some where else then you will need to pick and pass data from each and every array. In the case of data model you just need to pass an object.

One more thing, assume that User may have 20 to 50 properties in that case you need to create same numbers of array for that. is it efficient way?

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

Comments

2

Second option is the best. You organize all the items in structs and code is better and more clear. If your information is linked between their, better.

Comments

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.