UI Connections in Script Class

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

OK update to earlier posts.

When I remove the xib file loading code.

current application’s NSBundle’s loadNibNamed:(“OtherView”) owner:(me)

Then the Error message about the unkown class does not appear any more.

But with the downside that I end up with a xib file with a custom view in it that can’t be used.
Because it hasn’t been loaded.

AAAHHHHH

Mark

We can’t answer that until you show us the code. And as I keep saying, it’s not that IB doesn’t like it – it’s that it can’t find it because it isn’t loaded.

the main XIB is specified in Info.plist, so it’s loaded automatically during the launch process.

Another problem could be that any custom object (blue cube) is instantiated implicitly as well.
Try to Implement the standard init method in the custom class “ which is also called automatically “ and load the XIB from there

As already stated Shane, there is no code to show, it’s an empty brand new ASOC project other than the two lines as listed above previously.

AppDelegate.


script AppDelegate
use AppleScript version "2.4"
use scripting additions
    
property parent : class "NSObject"
property myClassScript : current application's MyClassScript
	
-- IBOutlets
property theWindow : missing value
	
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:
    
on applicationWillBecomeActive:aNotification

end applicationWillBecomeActive:
    
on applicationDidBecomeActive:aNotification
    
end applicationDidBecomeActive:
    
on applicationShouldTerminate:sender
    return current application's NSTerminateNow
end applicationShouldTerminate:
	
end script

The newley added script class.


script MyClassScript
use AppleScript version "2.4"
use scripting additions
    
property parent : class "NSObject"
    
end script

As you can see, it’s not a problem with any code written, it’s a problem with adding a reference to the MyClassScript class via a blue cube object in any xib file within the project.
You can add a reference to the AppDelegate script class within any xib file in the project. but not any newley created script class’s.

Yes Stefan I did try adding an “on init()” method to the new script class, and loading the xib file from their, but you still get the same error message about unknown script class.
Yes I did check out the info.plist file and could see that the MainMenu xib is loaded automatically on application start up.
and according to the developer docs, you load any new xib’s with either the NSBundle’s methods, or NSNib’s methods.

How I see it is, how do you make the blue cube script object reference acceptable in the xib file, in the same way as the AppDelegate script reference is.
And on that one, I just can’t figure it out the difference.

It’s also worth me re mentioning, that you don’t even have to add any new xib’s, the new script object is equally unwelcomed in the MainMenu xib file as well.

Regards Mark

Actually you don’t need a custom object (blue cube).
Make the XIB a subclass of NSViewController and MyClassScript a subclass of NSView.
Then set the class of the view to MyClassScript and you have access to all properties of the view.
The view itself is connected to property view of NSViewController

You can load the controller with


set otherViewController to current application's NSViewController's alloc()'s initWithNibName:("OtherView") bundle:(missing value)
set otherView to otherViewController's view()

Mark, I’m really not asking just to annoy you…

No, that’s incorrect. Because of the way AppleScript treats case, you should probably use a different name. But more importantly, the property should be set to missing value. You’re making the connection to the class in Interface Builder, so you need an outlet.

But I’m confused. If I open your script as posted in a script editor, that line doesn’t even compile – it would have to be something like property myClassScript : current application’s class “MyClassScript”.

As an aside for anyone following along, the practice of defining properties as references to classes is best avoided. Apart from anything else, it causes problems if you try doing it outside Xcode.

Hi Shane.

I know your not trying to be being pedantic, but I did post the only code changes to the new ASOC project previously, I think you misunderstood, this project with the MyClassScript is just a test project, the larger more comprehensive app I’m creating does not use this named script, the script classes in the proper app I’m working on are named totally different.
This MyClassScript is just a quick testing process, for the blue cube reference issue.
In the larger app project their are several scripts that need to be initiated and used immediately upon the App starting, so in setting them to missing value, I would then need to reset them straight away to the current application’s scriptClassNames, so I decided to make them point to their respective scripts in the propertry declaration.
I’ve not had a problem with this technique, and they do compile and work as expected when using Xcode, I’ve not tried it in AppleScript Editor, and in all honesty, I don’t really need to.
The other thing about the real app project is, that all of the other script class files are purely functional, where their methods are called by the AppDelegate, and they return analyised sorted and formatted data to the AppDelegate, and from there the AppDelegate displays this data in various Text Views and Text Fields, I was simply trying to find a way for these functional scripts to update the UI display themselves, rather than sending the data back to the AppDelegate to display.
So I was simply asking why the blue cube script reference system that the AppDelegate uses, does not work with any other scripts.
And thanks for all your help.

Hi Stefan.

Thanks for that, it did occure to me to sublclass NSView, but I’ve always found subclassing a bit of ovekill when your only just trying to access IBOutlet properties, the original project I wanted to use the technique with, may have as many as six different views, so a lot of subclasing will be required.
But because I’ve not found any other simple way to access UI components form new script classes, I will probably have to use this method, so thanks for showing the best way to implement this.

I would still desperately loved to know why new script class’s are not accepted by a xib file, when the AppDelegate which at the end of the day is just a script, is accepted in xib files, it’s very odd.

Many Thanks

Regards Mark