ios - How to add an index to an NSMutableArray based on value in another array? -


i've looked @ lots of questions ns(mutable)arrays. guess not grokking concept, or questions don't seem relevant.

what i' trying following:

incoming array 1:

name code start time end time etc

incoming array 2

code ordinal

what want:

ordinal name code start time end time etc

this code @ present:

int i=0; (i=0; < stationlistarray.count; i++) {     nsstring *slcodestring = [stationlistarray[i] valueforkey:@"code"];     nslog(@"slcodestring: %@", slcodestring);     int j=0;     (j=0; j< linesequencearray.count; j++) {         nsstring *lscodestring = [linesequencearray[j]valueforkey:@"stationcode"];         nslog(@"lscodestring: %@", lscodestring);         if ([slcodestring isequaltostring:lscodestring]) {             nslog(@"match");             nsstring *ordinalstring = [linesequencearray[j] valueforkey:@"seqnum"];             nslog(@"ordinalstring: %@", ordinalstring);             [stationlistarray[i] addobject:ordinalstring]; <------         }     } } 

i'm logging values , return correctly. compiler doesn't last statement. error:

[__nscfdictionary addobject:]: unrecognized selector sent instance 0x7f9f63e13c30  *** terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[__nscfdictionary addobject:]: unrecognized selector sent instance 0x7f9f63e13c30' 

here excerpt stationlistarray:

(         {         address =         {             city = greenbelt;             state = md;             street = ".....";             zip = 20740;         };         code = e10;         lat = "39.0111458605";         lon = "-76.9110575731";         name = greenbelt;     }    ) 

        nsstring *ordinalstring = [linesequencearray[j] valueforkey:@"seqnum"]; //is nsstring         [stationlistarray[i] addobject:ordinalstring];//<----- trying call addobject method of nsmutablearray on nsdictionary -> not  

when [stationlistarray[i] nsdictionary in case (generally returns nsobject inside nsarray @ given index, in case nsdictionary).

so in order complete desired operation: should make nsmutabledictionary instance (in case should mutablecopy stationlistarray[i]'s nsobject nsdictionary, when mutablecopy copies entire nsdictionary , makes mutable) make changes on , assign in stationlistarray[i]

for example:

nsmutabledictionary * tempdict = [[stationarray objectatindex:i]mutablecopy];//create mutable copy of `nsdictionary` inside `nsarray` [[tempdict setobject:ordinalstring forkey:@"ordinal"]; //in line adding ordinal `nsstring` in tempdict `nsmutabledictionary` have desired `nsmutabledictionary`. can change key whatever wish. [stationarray replaceobjectatindex:i withobject:[tempdict copy]];//swap original(old nsdictionary) new updated `nsmutabledictionary` used copy method in order replace immutable `nsdictionary` 

Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -