Sunday, May 9, 2021

#1 2021-05-01 10:23:25 am

rickzu
Member
From:: Atlanta
Registered: 2004-08-13
Posts: 15

xcode asobjc create "Preferences..." window

I'm looking for instructions/tutorial on how to create the "Preferences..." window (with tabs) in Xcode using asobjc. I know how to use the interface builder but "Preferences..." seems a special thing. I can find same for Swift, etc. but can't figure out how to translate to and do in asobjc. Bought Shane's book (2ed when it came out) but couldn't solve from there.

I just barely know what I'm doing so I suspect I'm missing something obvious. I would greatly appreciate any help.


Filed under: xcode asobj

Offline

 

#2 2021-05-02 11:51:52 am

Mark FX
Member
From:: UK
Registered: 2011-08-12
Posts: 118

Re: xcode asobjc create "Preferences..." window

You could fill an entire chapter of a book with what you're asking, so a tutorial in a forum would be totally unpractical, especially as there are a number of different approaches you could use.
if you can find tutorials in Swift or ObjectiveC that you think will work for your project, then you could use them as your guide, and ask on the forum about converting the code to ASOC code.

From my own experience and memory of ASOC projects in the past, trying to use xib files and ASOC classes outside of the AppDelegate script, for other windows and their UI can be problematic.
I do most of my projects in Swift these days, so I would be happy to try and help with the code conversion.

You should look into examples of using "NSUserDefaultsController" and or "NSUserDefaults".
You should find tutorials on the interweb for these Foundation classes.
If you have Shane's book, then I'm sure there must be something on "NSUserDefaults" in the book.
Or you could create your own preferences solution with plist files loaded and saved in the the Users Application Support Folder.

The preferences window is simply just that, an "NSWindow" with either a toolbar for swapping out views, or a tab controller as the content view of the window.
So you should be able to create a preferences window fairly quickly in Interface Builder.

Sorry I could not help more at this point, but finding a good simple tutorial online would be the best approach, and then post a link to a tutorial for help with the code conversion.

Regards Mark

Last edited by Mark FX (2021-05-02 12:00:24 pm)

Offline

 

#3 2021-05-02 03:52:41 pm

rickzu
Member
From:: Atlanta
Registered: 2004-08-13
Posts: 15

Re: xcode asobjc create "Preferences..." window

Hi Mark. Thanks for taking the time. You've helped me clarify what I'm after - I can create the Preferences window in Interface Builder, but what I need is a way to connect it the "Preferences..." menu item. I think that's all. In the video below using Swift at about 3:56 the person uses "PreferencesViewController" as the class of the window (subclass "NSViewController") and that seems to make that menu-item-to-window connection.

https://youtu.be/raLK95FyQso?t=228

I've built the app interface in asobjc and running out of time to learn and switch to Swift (SwiftUI?) - though it sounds like the direction I should be moving.

This is my first app in Xcode and I'm sort of limping my way through just to get a more complicated interface on my AS app.

Thank you for your time. Really.

Offline

 

#4 2021-05-02 05:23:21 pm

Mark FX
Member
From:: UK
Registered: 2011-08-12
Posts: 118

Re: xcode asobjc create "Preferences..." window

That video link is showing a project using storyboards for the UI design, you just can't do that with an ASOC project.
Most of the time you can convert Swift code to ASOC code, but you can't use SwiftUI techniques with an ASOC project.

Unfortunately with ASOC projects, you have to do it the old fashioned manual way with xib files.
I started a new ASOC project today for the first time in 18 months, just to try and refresh my memory on how your task can be achieved, and I remembered why I converted my ASOC projects over to Swift.
Xcode is the worst AppleScript editor you could use, but is needed for Interface Builder in order to add the UI to ASOC projects.

If I could send you the very basic Xcode project I created, you could see how to achieve the preferences interface you after, but to describe the process I had to go through wold not be practical for a forum posting.

But if I understand your question correctly, to link a menu item to a ASOC class function, you have to click and highlight the "Preferences" menu item, then right click and select the round dot, and drag to the ASOC class object, this could possibly be the AppDelegate blue square object, and then select the function name you want to activate from the list.

And with that description, you can see why a forum is not the best place to describe visual things.

I could post a picture somewhere, but I'm not sure where at this point.

I hope that lame description helps somewhat.

Regards Mark

Last edited by Mark FX (2021-05-02 05:35:27 pm)

Offline

 

#5 2021-05-02 05:32:01 pm

Mark FX
Member
From:: UK
Registered: 2011-08-12
Posts: 118

Re: xcode asobjc create "Preferences..." window

This image might help you with my lame description of the process.

https://ibb.co/1fMxsfQ

In the image you can see the "Preferences" menu item highlighted, and right clicked, and the round action dot you click and drag from to the AppDelegate blue square object, with the list of functions that can be selected for the menu item, and in this case I selected the bottom displayPreferencesWindow: function.

Hope that helps a bit more.

It's late here now, so will look in on the forum posting tomorrow.

Regards Mark

Last edited by Mark FX (2021-05-02 05:51:41 pm)

Offline

 

#6 2021-05-02 05:59:34 pm

rickzu
Member
From:: Atlanta
Registered: 2004-08-13
Posts: 15

Re: xcode asobjc create "Preferences..." window

Hi Mark. I think I follow everything but can't get the list of functions that I see in your screen shot. I hate to be a bother but I'd like to take you up on sending me your test basic Xcode project.

Can't thank you enough for sticking in there with me. After this project I'm moving to Swift!

Last edited by rickzu (2021-05-03 05:42:19 am)

Offline

 

#7 2021-05-02 06:21:11 pm

Mark FX
Member
From:: UK
Registered: 2011-08-12
Posts: 118

Re: xcode asobjc create "Preferences..." window

This is a link to the very basic bare bones skeleton of a ASOC project.
The project does absolutely nothing, other than show you how to display a preferences window from the mainMenu xib file.
It was created in Xcode 11 on Mojave just for you, so if your on a different MacOS version it may not be compatible.

The main parts for you to focus on are the blue square object references created in the mainMenu xib file, and the connections made to the two applescripts in the project, they are the key parts to a simple one xib file approach.

In this skeleton project, you would use the PreferencesManager.applescript to do all of your preferences data storage and saving work, and would have to add the necessary UI object connections from the Preferences window views, to new added functions within this PreferencesManager.applescript file.

If I can expand the simple project further for your better understanding, please let me know.

https://drive.google.com/file/d/1LUGxvb … sp=sharing

Sorry I ballsed up the link to the zip file, try downloading it again.

Regards Mark

Last edited by Mark FX (2021-05-02 07:13:48 pm)

Offline

 

#8 2021-05-02 06:57:00 pm

rickzu
Member
From:: Atlanta
Registered: 2004-08-13
Posts: 15

Re: xcode asobjc create "Preferences..." window

Yes! Worked beautifully! I don't know what I could ever do for you in return but if there is something please just ask. Thank you so much Mark. Take care and good night.

Offline

 

#9 2021-05-02 07:11:53 pm

Mark FX
Member
From:: UK
Registered: 2011-08-12
Posts: 118

Re: xcode asobjc create "Preferences..." window

Hey No Problem, I like a challenge.
And ASOC in Xcode can be a real challenge.


Just a note for anyone reading this last posting, the image file link will fail to work after one week, because the third party image hosting site has a time limit on their image links.
And the basic Xcode project link is stored in my personal Google Drive account, so at some point I will be removing this file from my account, so this link will also stop working.
Anyone who wants to host these files for future use is welcome to do so.

Regards Mark

Last edited by Mark FX (2021-05-04 08:45:45 am)

Offline

 

#10 2021-05-06 05:14:38 pm

technomorph
Member
Registered: 2017-12-14
Posts: 181

Re: xcode asobjc create "Preferences..." window

Stick with the learning Obj-C
I started in AppleScript then asobjc then into Xcode
I now almost exclusively program in objective c niw!

Offline

 

#11 Yesterday 05:24:21 pm

Mark FX
Member
From:: UK
Registered: 2011-08-12
Posts: 118

Re: xcode asobjc create "Preferences..." window

Don't waste your time with ObjectiveC.

That's the language of the past, embrace the future.

Regards Mark

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)