objective c - Initialising CoreData in AppleScript-objc -
i'm trying write , read coredata on osx, combinig cocoa classes applescript-objc. wrote methods handle coredata in tutorial (youtube, cocoa tutorial: core data introduction in ios , mac os programming part 2) <- cocoa classes in project
i have class called coredatahelper defines methods manipulate core data. here of them:
+(nsmanagedobjectcontext *) managedobjectcontext{ nserror*error; [[nsfilemanager defaultmanager] createdirectoryatpath:[coredatahelper directoryfordatabasefilename] withintermediatedirectories:yes attributes:nil error:&error]; if(error){ nslog(@"%@", [error localizeddescription]); return nil; } nsstring* path = [nsstring stringwithformat:@"%@/%@",[coredatahelper directoryfordatabasefilename],[coredatahelper databasefilename]]; nsurl *url = [nsurl fileurlwithpath:path]; nsmanagedobjectmodel* managedmodel = [nsmanagedobjectmodel mergedmodelfrombundles:nil]; nspersistentstorecoordinator* storecordinator = [[nspersistentstorecoordinator alloc] initwithmanagedobjectmodel:managedmodel]; if(![storecordinator addpersistentstorewithtype:nssqlitestoretype configuration:nil url:url options:nil error:&error]){ nslog(@"%@",[error localizeddescription]); return nil; } nsmanagedobjectcontext* managedobjectcontext = [[nsmanagedobjectcontext alloc] initwithconcurrencytype:nsmainqueueconcurrencytype]; return managedobjectcontext; } +(id)insertmanagedobjectofclass:(class) aclass inmanagedobjectcontext:(nsmanagedobjectcontext *)managedobjectcontext{ nsmanagedobject* managedobject = [nsentitydescription insertnewobjectforentityforname:nsstringfromclass(aclass) inmanagedobjectcontext:managedobjectcontext]; return managedobject; }
i'm using .xcdatamodeld model. have 2 entities in classes each 1 of them:
- tab
- service
tab.h looks this
#import <foundation/foundation.h> #import <coredata/coredata.h> @class service; ns_assume_nonnull_begin @interface tab : nsmanagedobject // insert code here declare functionality of managed object subclass @end ns_assume_nonnull_end #import "tab+coredataproperties.h"
and tab.m looks this:
#import "tab.h" #import "service.h" @implementation tab // insert code here add functionality managed object subclass @end
tab+coredataproperties.h:
#import "tab.h" ns_assume_nonnull_begin @interface tab (coredataproperties) @property (nullable, nonatomic, retain) nsstring *nzakladka; @property (nullable, nonatomic, retain) nsstring *uzakladka; @property (nullable, nonatomic, retain) service *podstronaserwisu; @end ns_assume_nonnull_end
tab+coredataproperties.m: #import "tab+coredataproperties.h"
@implementation tab (coredataproperties) @dynamic nzakladka; @dynamic uzakladka; @dynamic podstronaserwisu; @end
now, appdelegate.applescript looks this
... property coredatahelper: class "coredatahelper" property cservice: class "service" property ctab: class "tab" script appdelegate on applicationwillfinishlaunching_(anotification) set thecontext coredatahelper's managedobjectcontext() set cctab ctab's alloc()'s init() //the 1 below cause error "coredata: error: failed call designated initializer on nsmanagedobject class 'tab'" set thetab coredatahelper's insertmanagedobjectofclass_inmanagedobjectcontext_(cctab, thecontext) end applicationwillfinishlaunching_ ... end script
when run whole thing got error message posted in commented line in applescriptobjc code. method causing error nsmanagedobject* managedobject = [nsentitydescription insertnewobjectforentityforname:nsstringfromclass(aclass) inmanagedobjectcontext:managedobjectcontext];
problem?
Comments
Post a Comment