ios - How to replace object index in NSMutableArray in iPhone -


i have 2 different arrays , want check firstarray objects , accordingly insert objects in second array.if firstarray contains particular object @ index, trying insert value in secondarray. currently, inserting values :

[secondarray replaceobjectatindex:0 withobject:transidarray]; [secondarray replaceobjectatindex:1 withobject:fullcasearray]; [secondarray replaceobjectatindex:2 withobject:casetitlearray]; [secondarray replaceobjectatindex:3 withobject:filingdatearray]; 

my problem is, if in firstarray transidarray @ 2 index these 2 arrays data getting mismatched.please suggest me better way check add insert values in arrays. thanks.

nsarray elements naturally packed together, not sparse, c arrays can be. accomplish want, secondarray needs carry placeholders considered non-objects semantically app. [nsnull null], instance of nsnull (not confused nil) common choice.

you initialize 1 or both arrays this:

for (nsinteger i=0, i<some_know_max_length; ++i) {     [secondarray addobject:[nsnull null]]; } 

then instance of nsnull in second array means 'there's nothing @ index in array corresponding firstarray'. , can check if condition holds given index this:

id secondarrayelement = secondarray[index]; if ([secondarrayelement ismemberofclass:[nsnull class]]) { // ... 

as aside - often, when find myself needing coordinate parallel arrays, means have undone representational work, , need single array more thoughtful object, or containing object must more thoughtfully designed.


Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -