ios - Error during storing values in plist file -
i have stepper, during change of value need store values in plist.
so according saveappplist method need pass nsmutabledictionary changed file -> dictdata
nsdata *plistdata = [nspropertylistserialization datafrompropertylist:dictdata format:nspropertylistxmlformat_v1_0 errordescription:&error]; if(plistdata) { [plistdata writetofile:plistpath atomically:yes]; }
and here method stepper:
-(void)changeitemquantityatrow:(int)row tovalue:(double)value { nsmutabledictionary *item = [[items objectatindex:row] mutablecopy]; [item setobject:[nsnumber numberwithdouble:value] forkey:@"quantity"]; [items setobject:item atindexedsubscript:row]; nslog(@"%@", items); nsmutabledictionary *plistdict = [nsdictionary dictionarywithobjects:items forkeys:[nsarray arraywithobjects:@"name", @"price", @"quantity", nil]]; nslog(@"%@", plistdict); [self saveappplist:plistdict]; }
and plist looks (this 1 of 4 items):
<dict> <key>items</key> <array> <dict> <key>name</key> <string>the 0 item</string> <key>price</key> <integer>133</integer> <key>quantity</key> <integer>17</integer> </dict>
the stepper changing quantity of item. have error when try change value of quantity:
'nsinvalidargumentexception', reason: '*** -[nsdictionary initwithobjects:forkeys:]: count of objects (4) differs count of keys (3)'
i understand source of error don't know how can solve issue. can me? , 1 more - may it's not store value after every tap on stepper?
forget want store array, think of object id
instance. want store id items
key @"items"
, want use
//[nsdictionary dictionarywithobject:<#(id)#> forkey:<#(id<nscopying>)#>] nsmutabledictionary *plistdict = [nsdictionary dictionarywithobject:items forkey:@"items"];
Comments
Post a Comment