How to Retrive and Store NSArray from sqlite DB in iOS -


i have array itemqtyarray storing in sqlite table as:

    nsdata *todata = [nskeyedarchiver archiveddatawithrootobject:self.itemqtyarray];      nsstring *insertsql = [nsstring stringwithformat: @"insert ordertable(itemdesc,itemqty)values( \"%@\",\"%@\");",datastring2,todata]; 

and retrieving :

    const void *itemqty = sqlite3_column_text(statement, 2);     nsinteger qtybytes = sqlite3_column_bytes(statement, 2);     nsdata *data2 = [nsdata datawithbytes:itemqty length:qtybytes];     nsarray *myarrayfromdb = [[nsarray alloc]init];     myarrayfromdb = [nskeyedunarchiver unarchiveobjectwithdata:data2];     [self.itemqtyarray addobjectsfromarray:myarrayfromdb]; 

but getting exception @ line

    myarrayfromdb = [nskeyedunarchiver unarchiveobjectwithdata:data2]; 

terminating app due uncaught exception 'nsinvalidargumentexception', reason:

    '-[__nscfdata objectforkey:]: unrecognized selector sent instance 

please tell wrong

nsdata *todata = [nskeyedarchiver archiveddatawithrootobject:array]; 

instead of should pass nsdictionary

nsdata *todata = [nskeyedarchiver archiveddatawithrootobject:dictionary]; 

or

o convert generic array nsdata, need archiver! if know how feed nsdata, know how use nskeyedarchiver. so:

nsarray* array= ... ; nsdata* data=[nskeyedarchiver archiveddatawithrootobject:array]; 

of course elements in array needs implement nscoding protocol


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -