ios - [__NSCFNumber length]: unrecognized selector sent to instance with NSUserDefaults -
i creating 1 app in saving array of custom object in nsuserdefaults using below code :
[util setsubproductsarraypreference:myarray forkey:productid];
//util.m
+(void)setsubproductsarraypreference:(nsmutablearray *)subproducts forkey:(nsstring *)string { (int i=0; i<subproducts.count; i++) { subproducts *po=[subproducts objectatindex:i]; nsstring *st=[nsstring stringwithformat:@"%d",i]; [util setsubproductspreference:po forkey:st]; } nsuserdefaults *prefs = [nsuserdefaults standarduserdefaults]; nsdata *myencodedobject = [nskeyedarchiver archiveddatawithrootobject:subproducts]; [prefs setobject:myencodedobject forkey:string]; [prefs synchronize]; } +(void)setsubproductspreference:(subproducts *)subproducts forkey:(nsstring *)key { nsuserdefaults *prefs = [nsuserdefaults standarduserdefaults]; nsdata *myencodedobject = [nskeyedarchiver archiveddatawithrootobject:subproducts]; [prefs setobject:myencodedobject forkey:key];//here crashing [prefs synchronize]; }
this code working fine ios7 , prior..the problem when running same code ios8 in xcode6 getting below error :
-[__nscfnumber length]: unrecognized selector sent instance 0xb000000000000f23 *** terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[__nscfnumber length]: unrecognized selector sent instance 0xb000000000000f23' *** first throw call stack: ( 0 corefoundation 0x00000001042fbf35 __exceptionpreprocess + 165 1 libobjc.a.dylib 0x0000000103bbabb7 objc_exception_throw + 45 2 corefoundation 0x000000010430304d -[nsobject(nsobject) doesnotrecognizeselector:] + 205 3 corefoundation 0x000000010425b27c ___forwarding___ + 988 4 corefoundation 0x000000010425ae18 _cf_forwarding_prep_0 + 120 5 corefoundation 0x00000001042bc790 _cfprefsencodekeyvaluepairintomessage + 64 6 corefoundation 0x00000001042fe286 -[cfprefsplistsource sendmessagesettingvalue:forkey:] + 102 7 corefoundation 0x000000010423cef7 -[cfprefsplistsource alreadylocked_setvalue:forkey:] + 215 8 corefoundation 0x000000010423cdee -[cfprefssource setvalue:forkey:] + 62 9 corefoundation 0x00000001041fa1f8 +[cfprefssource withsourceforidentifier:user:byhost:container:perform:] + 1112 10 corefoundation 0x000000010423cd63 _cfpreferencessetvaluewithcontainer + 227 11 foundation 0x000000010374099b -[nsuserdefaults(nsuserdefaults) setobject:forkey:] + 46 12 hp protrain 0x0000000101186787 +[util setsubproductsarraypreference:forkey:] + 487 13 hp protrain 0x0000000101115a38 __74-[desktopproductsviewcontroller fetchingproductsubcategorydatafromserver:]_block_invoke_2 + 3096 14 libdispatch.dylib 0x00000001051b4ba6 _dispatch_call_block_and_release + 12 15 libdispatch.dylib 0x00000001051d27f4 _dispatch_client_callout + 8 16 libdispatch.dylib 0x00000001051bb8fb _dispatch_main_queue_callback_4cf + 949 17 corefoundation 0x0000000104263fe9 __cfrunloop_is_servicing_the_main_dispatch_queue__ + 9 18 corefoundation 0x0000000104226eeb __cfrunlooprun + 2043 19 corefoundation 0x0000000104226486 cfrunlooprunspecific + 470 20 graphicsservices 0x00000001082c29f0 gseventrunmodal + 161 21 uikit 0x0000000102463420 uiapplicationmain + 1282 22 hp protrain 0x00000001010c1a87 main + 151 23 libdyld.dylib 0x0000000105207145 start + 1 ) libc++abi.dylib: terminating uncaught exception of type nsexception
do 1 else experience same problem?
change line
[util setsubproductsarraypreference:myarray forkey:[nsstring stringwithformat:@"%@",productid]];
Comments
Post a Comment