ios - [__NSCFArray objectForKey:]: unrecognized selector sent to instance when fetching from Core Data -
i getting error [__nscfarray objectforkey:]: unrecognized selector sent instance
when trying fetch data core data
.
i relatively new ios programming , don't quite understand error trying tell me. set exception breakpoint
figure out line giving me problem , line of code:
if let fetchresults = managedobjectcontext!.executefetchrequest(fetchrequest, error: nil) as? [user] {
why getting error , how resolve it? related way save core data
? did change receive json server, process in background , save changes managedobjectcontext
in main thread.
func getuser(userid: string) -> user? { let fetchrequest = nsfetchrequest(entityname: "user") fetchrequest.predicate = nspredicate(format: "userid == %@", userid) fetchrequest.fetchlimit = 1 if let fetchresults = managedobjectcontext!.executefetchrequest(fetchrequest, error: nil) as? [user] { if !fetchresults.isempty { return fetchresults[0] } else { println("userid \(userid) not in database") } } return nil }
error
2014-12-06 13:09:36.087 lfdate[3162:51570] -[__nscfarray objectforkey:]: unrecognized selector sent instance 0x7fb9e95c4310 2014-12-06 13:09:36.090 lfdate[3162:51570] *** terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[__nscfarray objectforkey:]: unrecognized selector sent instance 0x7fb9e95c4310' *** first throw call stack: ( 0 corefoundation 0x00000001025c2f35 __exceptionpreprocess + 165 1 libobjc.a.dylib 0x000000010465ebb7 objc_exception_throw + 45 2 corefoundation 0x00000001025ca04d -[nsobject(nsobject) doesnotrecognizeselector:] + 205 3 corefoundation 0x000000010252227c ___forwarding___ + 988 4 corefoundation 0x0000000102521e18 _cf_forwarding_prep_0 + 120 5 corefoundation 0x000000010248beaf cfdictionarygetvalue + 159 6 foundation 0x0000000102befd78 -[nskeyedunarchiver initforreadingwithdata:] + 1698 7 foundation 0x0000000102c135ea +[nskeyedunarchiver unarchiveobjectwithdata:] + 66 8 coredata 0x000000010210b4e0 _prepareresultsfromresultset + 3552 9 coredata 0x0000000102108930 newfetchedrowsforfetchplan_mt + 3296 10 coredata 0x00000001020f53ac -[nssqlcore objectsforfetchrequest:incontext:] + 524 11 coredata 0x00000001020f4e2b -[nssqlcore executerequest:withcontext:error:] + 299 12 coredata 0x00000001021ca4f3 __65-[nspersistentstorecoordinator executerequest:withcontext:error:]_block_invoke + 3331 13 coredata 0x00000001021d27ee gutsofblocktonspersistentstorecoordinatorperform + 190 14 libdispatch.dylib 0x00000001052117f4 _dispatch_client_callout + 8 15 libdispatch.dylib 0x00000001051f8774 _dispatch_barrier_sync_f_invoke + 365 16 coredata 0x00000001021c53d5 _perform + 197 17 coredata 0x00000001020f4ac8 -[nspersistentstorecoordinator executerequest:withcontext:error:] + 504 18 coredata 0x00000001020f33e0 -[nsmanagedobjectcontext executefetchrequest:error:] + 544 19 lfdate 0x0000000101b9c3b3 _tfc6lfdate14databasehelper7getuserfs0_fssgsqcs_4user_ + 1075 20 lfdate 0x0000000101c4ce01 _tfc6lfdate23menutableviewcontroller9tableviewfs0_ftcso11uitableview21cellforrowatindexpathcso11nsindexpath_cso15uitableviewcell + 4689 21 lfdate 0x0000000101c4e4ff _ttofc6lfdate23menutableviewcontroller9tableviewfs0_ftcso11uitableview21cellforrowatindexpathcso11nsindexpath_cso15uitableviewcell + 79 22 uikit 0x000000010349d4b3 -[uitableview _createpreparedcellforglobalrow:withindexpath:willdisplay:] + 508 23 uikit 0x000000010347cfb1 -[uitableview _updatevisiblecellsnow:isrecursive:] + 2846 24 uikit 0x0000000103492e3c -[uitableview layoutsubviews] + 213 25 uikit 0x000000010341f973 -[uiview(calayerdelegate) layoutsublayersoflayer:] + 521 26 quartzcore 0x000000010318ade8 -[calayer layoutsublayers] + 150 27 quartzcore 0x000000010317fa0e _zn2ca5layer16layout_if_neededepns_11transactione + 380 28 quartzcore 0x000000010317f87e _zn2ca5layer28layout_and_display_if_neededepns_11transactione + 24 29 quartzcore 0x00000001030ed63e _zn2ca7context18commit_transactionepns_11transactione + 242 30 quartzcore 0x00000001030ee74a _zn2ca11transaction6commitev + 390 31 quartzcore 0x00000001030eedb5 _zn2ca11transaction17observer_callbackep19__cfrunloopobservermpv + 89 32 corefoundation 0x00000001024f7dc7 __cfrunloop_is_calling_out_to_an_observer_callback_function__ + 23 33 corefoundation 0x00000001024f7d20 __cfrunloopdoobservers + 368 34 corefoundation 0x00000001024edb53 __cfrunlooprun + 1123 35 corefoundation 0x00000001024ed486 cfrunlooprunspecific + 470 36 graphicsservices 0x00000001072f09f0 gseventrunmodal + 161 37 uikit 0x00000001033a6420 uiapplicationmain + 1282 38 lfdate 0x0000000101be33ae top_level_code + 78 39 lfdate 0x0000000101be33ea main + 42 40 libdyld.dylib 0x0000000105246145 start + 1 41 ??? 0x0000000000000001 0x0 + 1 ) libc++abi.dylib: terminating uncaught exception of type nsexception
Comments
Post a Comment