A few weeks ago I made a little Core Data application in XCode which has been working fine. It’s a little app that helps me keep track of my projects. The problem started when I decided I didn’t no longer wanted to type in the path to a project folder, I wanted to do a choose folder and store the result in my app and do useful stuf with it, preferably in Applescript of course, since I’ve no experience in Cocoa programming. (I posted this problem to the Cocoa-Dev list as well, but I guess they want nothing to do with applescripters).
Anyway, I soon found out that for that I needed to subclass my entity Projecten (the app speaks Dutch, as do I) and that ProjectBuilder very gallantly writes all the code if one selects the data model and chooses File >> New File > Managed Object Class. So now I have Projecten.h and Projecten.m with all the setters and getters, like so:
Projecten.m —I didn’t write this, Xcode did, so it should be good-------------------------
NSString * tmpValue;
[self willAccessValueForKey: @“projectFolder”];
tmpValue = [self primitiveValueForKey: @“projectFolder”];
[self didAccessValueForKey: @“projectFolder”];
[self willChangeValueForKey: @“projectFolder”];
[self setPrimitiveValue: value forKey: @“projectFolder”];
[self didChangeValueForKey: @“projectFolder”];
The problem, however, is that no matter what I do I cannot seem to get “setProjectFolder:” to do anything. I have a button to whose on Click I’ve attached the following applescript, which achieves exactly nothing: no errors, but no result either:
on clicked theObject if the name of theObject is "AddProjectFolder_btn" then local strProjectFolder set strProjectFolder to (choose folder) as string call method "setProjectFolder:" of class "Projecten" with parameter strProjectFolder end if end clicked
I’ve read Jobu’sHow to create an Objective-C subclass on http://applescriptsourcebook.com/viewtopic.php?id=17559, and I’ve tried subclassing NSManagedObjectContext in IB. I’ve called the subclass “Projecten” and I’ve added an action called setProjectFolder:. When click on the View in editor button in the Inspector, XCode does open up Projecten.m, which gave me hope, but still call method “setProjectFolder:” of class “Projecten” produces nothing and neither does
call method "projectFolder" of class "Projecten"
Before this I tried another route: I connected the “Awake on nib” action of the Projecten Array Controller to my Projecten_view.applescript. The results seemed hopeful at first but in the end led me nowhere.
on awake from nib theObject log (call method "entityName" of theObject) -- returns "Projecten" set objMOC to call method "managedObjectContext" of theObject log (call method "hasChanges" of objMOC) -- returns 0 end awake from nib
This seems encouraging, but when I store objMOC in a property and then later, for instance in the onClick handler, ask it again to
log (call method "hasChanges" of objMOC) -- returns
again nothing happens: no errors, no results. I really hope someone can shine a light on this, because I’m out of ideas. Core Data is good but if I could figure this out, it would come close to perfection.