ios - Objective-c newbie - UIViewController managedObjectContext unrecognized selector sent to instance -


using code below following error:

2016-04-25 10:04:51.520 ecoss[1700:620301] -[__nscfstring managedobjectcontext]: unrecognized selector sent instance 0x160383a0 objc[1700]: exceptions: throwing 0x14f94500 (object 0x14d07b70, nsexception) objc[1700]: exceptions: searching through frame [ip=0xffffffff sp=0x26a0b0] exception 0x14f944e0 objc[1700]: exceptions: searching through frame [ip=0x2 sp=0x26b980] exception 0x14f944e0 objc[1700]: exceptions: unwinding through frame [ip=0xffffffff sp=0x26a0b0] exception 0x14f944e0 objc[1700]: exceptions: unwinding through frame [ip=0x2 sp=0x26b980] exception 0x14f944e0 objc[1700]: exceptions: handling exception 0x14f944e0 @ 0x231e33b9 objc[1700]: exceptions: rethrowing current exception objc[1700]: exceptions: searching through frame [ip=0x6 sp=0x26b980] exception 0x14f944e0 objc[1700]: exceptions: terminating objc[1700]: exceptions: searching through frame [ip=0x1 sp=0x26b820] exception 0x14f944e0 objc[1700]: exceptions: catch(id) objc[1700]: exceptions: unwinding through frame [ip=0x1 sp=0x26b820] exception 0x14f944e0 objc[1700]: exceptions: handling exception 0x14f944e0 @ 0x22a6f089 2016-04-25 10:04:51.582 ecoss[1700:620301] *** terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[__nscfstring managedobjectcontext]: unrecognized selector sent instance 0x160383a0' *** first throw call stack: (0x232d398b 0x22a6ee17 0x232d9325 0x232d6f51 0x232022f8 0x24dc0d9d 0x24dbffb1 0x5d06b 0x48f3d 0x48759 0x80a11 0x24d9b 0x27a70e61 0x27a70be7 0x27a70827 0x279e12fd 0x27a2ed13 0x279e12fd 0x27a2ed13 0x279e12fd 0x27a2ed13 0x27830e55 0x2786fde1 0x2786f593 0x27840055 0x2783e603 0x23295e6f 0x23295a5d 0x23293dcb 0x231e32e9 0x231e30d5 0x247d3ac9 0x278a80b9 0x1a4f1 0x22e8b873) libc++abi.dylib: terminating uncaught exception of type nsexception 

code

-(uiviewcontroller*) displayviewfromstring:(nsstring *) identifier {      ontracappdelegate* delegate = [ontracappdelegate sharedappdelegate];      nsmanagedobjectcontext* moc = delegate.managedobjectcontext;      if ([identifier isequaltostring:@"notes"]) {         viewcontroller = [[ontracpagenotesviewcontroller alloc] init];          nsstring *requesturl = [nsstring stringwithformat: @"http://mydomain/%i/true",self.dataobject.datapack.pack_id ];         nslog(@"%@", requesturl);         //the request built based on string         nsmutableurlrequest *request = [[nsmutableurlrequest alloc] initwithurl: [[nsurl alloc] initwithstring: requesturl]];         [request sethttpmethod:@"get"];         [request setvalue:@"application/x-www-form-urlencoded" forhttpheaderfield:@"content-type"];          nsdictionary *cookieproperties = [nsdictionary   dictionarywithobjectsandkeys:                                       @"cakephp", nshttpcookiename,                                       @"mydomain.co.uk", nshttpcookiedomain,                                       self.cookievalue, nshttpcookievalue,                                       @"/", nshttpcookiepath,                                       nil];         nshttpcookie *cookie = [nshttpcookie cookiewithproperties:cookieproperties];         nsarray* cookiearray = [nsarray arraywithobjects: cookie, nil];         nsdictionary * headers = [nshttpcookie requestheaderfieldswithcookies:cookiearray];         [request setallhttpheaderfields:headers];          nserror *err;         nsurlresponse *resp;         //the return data formatted json response         nsdata *returndata = [nsurlconnection sendsynchronousrequest: request returningresponse:&resp error:&err];         nserror *error;         nsdictionary *json = [nsjsonserialization                           jsonobjectwithdata:returndata                           options:kniloptions                           error:&error];            nsmutablearray *responseobjects = [json objectforkey:@"response"];           (dataobject *dataobject in responseobjects) {             //if ([dataobject.datapack.pack_id intvalue] == self.dataobject.datapack.pack_id){             nsarray * value = [responseobjects objectforkey:dataobject];             //nsstring *notestring = [[nsstring alloc] init] ;             nsstring *notecreated = [value objectforkey:@"created"];             nsarray *imagearray = [value objectforkey:@"images"];             nsstring *notestring = [value objectforkey:@"note"];             nsstring * noteupdated = [value objectforkey:@"updated"];              nslog(@"do %@", dataobject);              notes *note = [nsentitydescription insertnewobjectforentityforname:@"notes" inmanagedobjectcontext:moc];               nslog(@"%@", note);              note.notes = notestring;             note.noteid = [nsnumber numberwithinteger: dataobject];             //note.notes = self.textfield.text;             nsmutablearray * array = [[nsmutablearray alloc] init];             (nsstring *image in imagearray) {                  nsstring *image_created = [image objectforkey:@"created"];                 nsstring *image_id = [image objectforkey:@"id"];                 nsstring *image_data = [image objectforkey:@"image_data"];                 nsstring *image_type = [image objectforkey:@"image_type"];                  nslog(@"%@", image_id);                  nsdata *pngdata = [[nsdata alloc]initwithbase64encodedstring:image_data options:nsdatabase64decodingignoreunknowncharacters];                 nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes);                 nsstring *documentspath = [paths objectatindex:0]; //get docs directory                 nsstring *filepath = [documentspath stringbyappendingpathcomponent:[ nsstring stringwithformat:@"%@_%i_%@_notes_image.png", delegate.username, self.dataobject.datapack.pack_id, [self genrandstringlength:8]]]; //add file name                 [pngdata writetofile:filepath atomically:yes];                  [array addobject:filepath];              }             note.dataobject = dataobject;             note.imagelocations = [nskeyedarchiver archiveddatawithrootobject:array];         nslog(@"note %@", note);             [dataobject addnotesobject:note];            //}        }          //[[[splitview viewcontrollers] objectatindex:1]  pushviewcontroller:notesview animated:yes];     } } 

i have line break @ line (note.notes = notestring) when error produced. prior note object logged fine. want add data request it.

core data core data

notes.h

@class dataobject;  @interface notes : nsmanagedobject  @property (nonatomic, retain) nsdata * imagelocations; @property (nonatomic, retain) nsstring * notes; @property (nonatomic, retain) nsnumber * noteid; @property (nonatomic, retain) dataobject *dataobject;  @end 

notes.m

#import "notes.h" #import "dataobject.h"   @implementation notes  @dynamic imagelocations; @dynamic notes; @dynamic noteid; @dynamic dataobject;  @end 

managedobjectcontext - appdelegate.m

- (nsmanagedobjectcontext *)managedobjectcontext {  if (managedobjectcontext != nil) {     return managedobjectcontext; }  nspersistentstorecoordinator *coordinator = [self persistentstorecoordinator]; if (coordinator != nil) {     managedobjectcontext = [nsmanagedobjectcontext new];     [managedobjectcontext setpersistentstorecoordinator: coordinator]; }  return managedobjectcontext; } 

it appears issue data types messed up. json stuff listed nsdictionary, , try take out of nsmutablearray. isn't possible array me mutable current code.

you iterate array, , try treat contents dataobject instances, nsdictionary instances.

you're using responseobjects objectforkey:dataobject, apparently on array, call should work on dictionary. continue use objectforkey on code says array again should dictionary.

so, i'm kinda confused , unable issue is, think need verify class types you're working , make sure it's think is.


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -