iphone - Objective C plist searching and random entry -



iphone - Objective C plist searching and random entry -

another couple of questions plists , objective c iphone. both questions relate plist can seen in lastly last question.

first thing searching, know possible right way go this? should pull searchable objects array , utilize build table? or possible itereate through plist , show matches? or there other way missing here? quick illustration in next want bring 2 'jones' results:

<dict> <key>a</key> <array> <string>a jones</string> <string>a king</string> </array> <key>t</key> <array> <string>t jones</string> <string>t king</string> </array>

secondly, possible phone call random result plist, i'm pretty sure is, 1 time again right way go this?

i admit finding plist bit of pain seems me bit of rubbish form of xml. , still finding iterating through plist dictionary pretty confusing degree. still, thoughts on these 2 questions appreciated.

thanks :)

it possible iterate through nsdictionary values using -(nsenumarator *)objectenumerator;, can retrieve values -(nsarray *)allvalues; , have -(nsset *)keysofentriespassingtest:(bool (^)(id key, id obj, bool *stop))predicate; returns nsset containing keys value have passed test (from mac os x 10.6).

about sec question, think there's no 'better' way. here how :

get keys of nsdictionary using -(nsarray *)allkeys; get random number pick key in array using -(id)objectatindex:(nsuinteger)anindex; retrieve corresponding object in dictionary using : -(id)objectforkey:(id)akey;

then got object. hope helps.

edit:

here simple way iterate on values in nsdictionary :

// assuming have initialized dictionary // first create container nsmutablearray *selectedobjects = [[nsmutablearray alloc] init]; // retrieve enumerator dictionary nsenumerator *e = [thedictionary objectenumerator]; id anobject; // iterate... while((anobject = [e nextobject]) != nil) { // want object // in case each object array nsarray *thearray = (nsarray *)anobject; // ... // if find of them interesting set in first array if([[thearray objectatindex:0] isequaltostring:@"jones"]) { [selectedobjects addobject:[thearray objectatindex:0]]; } } // here selected objects in selectedobjects. // won't forget release selectedobjects when don't need anymore

iphone objective-c dictionary plist

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -