objective c - How to check whether data or object already exist in PList, iPhone? -


i can add , remove object or data in plist wanna know data or object exist in plist. code

nsuinteger countobjectsfromplist; countobjectsfromplist = [[mdict allkeys] count]; nslog(@"objects in plist %d", countobjectsfromplist); for(int i=0; <= countlawsfromplist; i++){ nslog(@"\n\n\n%d\n\n\n", i); //if([objectname isequaltostring:[[mdict allkeys] objectatindex:i]]) if(objectname ==[[mdict allkeys] objectatindex:i]){ nslog(@"already exists"); //nslog("string equal"); } else {  nslog(@"added favorites"); }  } 

please 1 me on come this. thanks

id object = [mdict objectforkey:key]; bool exists = (object != nil); 

edit: apparently wasn't clear enough. objectforkey you're telling dictionary "could please give me object key key"? if object there key, returning value non-nil. otherwise nil. that's why check object != nil in order know if object exists in dictionary key. goes take more coffee


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -