UI Connections in Script Class

I’m sure this has probably been asked before, but I can’t seem to find any relevant posts on this subject.

I want to connect user interface elements to properties in a ASOC class.
I can do this in the AppDelegate script via properties connected to interface elements in Interface Builder.
But I can’t seem to achieve these same connections in other scripts within the project, I’m missing something
simple, but for the life of me I can’t figure it out.

Any help would be appreciated.

Many Thanks Mark

Hi,

to be able to connect UI properties the class must be instantiated with a object (blue cube) in Interface Builder.

Yes I’ve used a blue object cube in the xib file in Interface Builder and set the blue objects class to my script class.
But get an error in the Xcode’s console window.

Unknown class StatisticsTextLoader in Interface Builder file at path /Users/Mark/Library/Developer/Xcode/DerivedData/ProjectName-cszkfvklebnfxoesfprsojhgxjst/Build/Products/Debug/ProjectName .app/Contents/Resources/Base.lproj/StatisticsTextDataView.nib.

So it seems that the script class is not being allowed to connect to the xib file for some reason.

Regards mark

Perhaps some more detail might be useful.
The project has a main Window and Main Menu in the main xib file, which has various IB connections to the AppDelegate script, which are all working fine, and as expected.

It also has two other xib files that contain only custom views, which are swapped with the Main Windows content view when certain toolbar buttons are clicked, all the view swapping happens in the AppDelegate script, and works fine.

the data content is also displayed in the custom views via the AppDelegate script, which also works fine, but as the
project grows, I want to move some of the data displaying code into other sript classes, as the AppDelegate script is becoming to large with code, which is also becoming a headache to manage and debug.

But the problem I’m having is trying to connect the usere interface elements to these other script classes.

Regards Mark

That sounds more like either you haven’t typed the class name in properly, or the class file isn’t set up properly. Does the class file begin with:

script StatisticsTextLoader

Sorry for the slow reply Shane.

Yes I’ve checked the obvious like spelling, the script is named like this.


script StatisticsTextLoader

-- Properties and Methods here

end script

When bringing the blue cube object into the xib file, and setting it’s class, the StatisticsTextLoader class is
also listed and selected in the pull down list of classes.

It seems like the only script I’m able to manipulate the UI elements with is the AppDelegate.
I stumped at this point.

Regards Mark

Is the Target Membership of the script enabled (File Inspector - ⌥⌘1 ) ?

Hi Stefan

I can’t find a Target Membership attribute in the blue cube object’s File Inspector.

Sorry I don’t understand your advice.

Regards mark

the script StatisticsTextLoader, not the object

Yes the Target Membership is set to the project the same as the AppDelegate and other scripts.

Regards Mark

Add a new class and try with it.

Hi Shane

Yes I have done that before already.

I’ve found with Xcode 6.11 that when you go to add a new file from an ASOC project, your not given any ASOC class file templates, and you have to choose the blank file template instead, which you then turn into a script yourself.
I don’t know if this is part of the problem, I seem to remember in earlier Xcode versions, being able to choose an Applescript class template when adding a new file to a project.

At the moment I’m sticking with my current technique for displaying text and data, as it is working, although it would have been nice to break down some of the UI code into different script objects.

The App upto now has been doing the data analaysis and number chrunching with only a small subset of the intended data it will finally have to deal with, only while I’ve been debugging the App, and yesterday I gave it a bigger load to manage, and it is creaking under the strain, and also taking forever to work through the data, so at this point I’m starting to think that Applescript will not be upto the final job anyway, and a faster multithreaded language might have to be used, so for the time being my original UI manipulation desires might have to take a back seat, While I try to decide wether to change the project into a different language.

But Thanks for the help anyway.

Regards Mark

Are you saving the class files as .applescript files?

Yes I am Shane, with a .appescript extension, although they start out life as a blank file template in Xcode 6.1.1.

Regards Mark

I hope there’s an "l’ in there :slight_smile:

In your app delegate, in its applicationWillFinishLaunching: handler, add:

current application's NSLog("%@", current application's StatisticsTextLoader's description())

That should give you an idea of whether the class has loaded properly. If not, there’s probably a problem in your class file.

Thanks Shane.

But for the moment I’ve ditched the StatisticsTextLoader class file and xib, and sticking with my current UI displaying methods in the AppDelegate, I’ve decided to work on improving the other data loading class’s performance, as data reading from files, and also data analysing code was performing to slowly and taking forever, so working on those aspects of the project at the moment, as they are more important.

Although I will be returning to my original UI displaying ideas posted here, and I will check my class spellings and description methods when that time arrives again.

Thanks again.

Regards Mark

After a few days from the original forum post question, dealing with speed performance issues with my app, which I’ve now resolved.
I started with a clean new ASOC project in Xcode, called just “Test.app”, in order to try to get my head around this Xib script class problem.

After adding a new Applescript class file to the basic ASOC project template, and also a new xib file with a custom view added to the project, when I add a blue object cube to the xib file, and set it’s class to the newley created Applescript class, why does the Xcode terminal window issue a warning about the blue cube objects class file.

This seems to be where the answer to my original question needs to be solved.

And as much as I’m grateful for the help and advice from Stefan and Shane, I have checked for the obvious spelling and typos.

How does the new Applescript class added to the project have to be set up, inorder for Interface Builder to accept it when associated to a blue cube object?

Regards Mark

It’s not really an Interface Builder problem – the problem is that the script class is not being loaded, and hence IB’s complaint that there is no such class.

Can you post the contents of the script file?

Hi Shane

As Stated above, its a barnd new ASOC project template, with no code in the newley added script file, other the script end script lines, and the newley added view xib file is as standard other than the blue cube object added, which is pointing to the empty of code new script class.

I’ve started this new standard ASOC project template to use as a test bed for this problem I’m struggling with, so that I can figure out what I need to do in the previously mentioned real project.

The only code added is in the AppDelegate script as listed below.


    on applicationWillFinishLaunching:aNotification
        my myClassScript's alloc()'s init()
    end applicationWillFinishLaunching:
    
    on applicationDidFinishLaunching:aNotification
        current application's NSBundle's loadNibNamed:("OtherView") owner:(me)
    end applicationDidFinishLaunching:

which initiates the newley added empty of code script class, and loads the newley added view xib file.

If I add a blue cube object in the project templates standard MainMenu.xib, ponting to the newley added script class, Xcode does not complain, but if you do the same thing in the newley added view xib file, Xcode does complain.

So in short I’m trying to figure out what the difference is between the standard MainMenu.xib file, and any newley added xib files.
And why you can add a reference to the AppDelegate script in any newley added xib files, but you can’t add the same type of reference to other script class files.

To duplicate this problem does not require any amount of code, you can simply start a new ASOC project, and add one new script class file, and one new view xib file.

Still scratching my head.

Regards Mark.

Correction Shane, the MainMenu xib also complains about the newley created script class object.

But you are able to add the AppDelegate script object to any xib file without complaint.

So what’s the difference between the AppDelegate script object, and any newley created script objects, that either the Interface builder or any xib file does not like.

Mark