Getting started in Fire/Swift

Hello again marc, I’m having problems getting started with Fire. I’ve setup Fire correctly, I think, although the following screen confused me:

In particular, the Cocoa Path edit box shows $(Fire.app)/Contents/Resources/Toffee SDKs in grey text. It isn’t clear whether this is the recommended entry here. It’s made more awkward by the fact that the text disappears as soon as you start typing. In any case, even if you try to enter $(Fire.app)/Contents/Resources/Toffee SDKs the entry isn’t retained the next time you go back into Fire preferences.

After I’ve created the project/solution I am presented with the following screen:

It seems a bit sparse compared to the image in the tutorial:

Anyhow, I decided to press on and did a Project -> Add New File. I accepted the defaults on the next screen and accepted the default filename of Codefile.swift. I then pasted in the "The magic happens here." piece of code from the tutorial. any attempts then to build or Run are met with an alarming error screen. The details of the error message seem to have changed now. Previously it talked about the Fire Setup not being correct. Now it looks like this:

I’m sure that it is just one simple mistake I have made that is causing me all these problems but I can’t figure out what. Over to you…

Cheers,
Carl

It’s the default value thats used when no value is provided.

which is why that happens. this is standard Cooca/macOS text control behavior fwiw.

you don’t need to provide any value here, unless you want to manually override the path.

It looks like you created an empty “Shared Project”, rather than a “Cocoa Application”? i.e. you used a different ./ the wrong template.

—marc

Finally, that last error looks lie you (somehow) ended up with two projects with then same name in the Solution.

I suggest to start fresh with “New Project” and make sure to uncheck “Add to existing solution”.

Ah! I think I see where I went wrong. On the following screen, I thought that selecting the Cocoa icon at the top would be enough:

I didn’t realise that there was a whole host of goodies lurking beneath the Template select box.

I’ve just tried it again, and it works. Hurrah!

Thanks,
Carl

:wink:

maybe i should rename that to something like “Project Type”?

:thumbsup:

Just one small question. Now that I can successfully create a Cocoa app with an empty window, where would you suggest is the best place to learn about adding labels and buttons and other controls? Also, would such information be specific to Fire or would generic Swift material help here?

Sorry if I’m being a bit dim, here, but I guess my brain hasn’t quite gelled with the Swift way of doing things yet.

Thanks,
Carl

Would I be right in thinking that I should use Xcode to define the UI elements and that this is done by opening the xib files in Xcode? Is there any form of synchronisation between Fire and Xcode, so that one can switch between them with single keypresses according to the task in hand?

It’s all so different from Delphi, that’s for sure!

Start here for Fire/Elements specific parts: , once you’re past that, any regular docs of for Apple Swift/Xcode/ObjC/Cocoa this will be useful.

Not at all.

Yes, changes will sync back and forth, once you have other open, you can just Cmd-tab between them as you need.

So, I discovered the select project, right click, Edit User Interface Files in Xcode method of getting into Xcode with all of the necessary UI files. Following a StackOverflow thread at https://stackoverflow.com/questions/29440821/xcode-way-to-print-hello-world-when-button-is-clicked-in-os-x-swift-applicatio I dropped an NSButton and a Label onto the form. On running that in Fire the update windows shows nicely.

The problem comes when I try to attach code to the button. At this point, the instructions in the SO thread lose connection with what I see on screen. The SO thread says this:

One thing to note is here we use NSButton.

In the storyboard, you should see a view controller (a yellow cube).

click on this view controller
check the right panel and the 3rd icon on the top. Click it
You will see "Custom Class" "Class" "Module"
In "Class", drop down and choose the view controller class you implemented
Make sure you implemented this buttonTap function in the class
In the storyboard make sure you see the button
hold the control key, click on the button and drag to the yellow cube
release your mouse
see the buttonTapped function show in the menu popping up
choose this function

It falls down at the second line. I don’t even see anything recognisable as the Storyboard, let alone the View Controller (yellow cube).

I swear sometimes that the end of the world will be caused by some piece of technical documentation not corresponding to actual reality! Or by a mistake involving diplomatic translators but that’s not relevant here!

Any ideas?

Thanks,
Carl

The link i send, and this one which is linked from there, should cover this?

Which is the link you sent?

Ah oops. my previous reply lost there link on “start here” somehow. https://docs.elementscompiler.com/Fire/ExternalDesigners/EditingCocoaXIBsAndStoryboardsInXcode/.

Ah! Excellent. I feel like I’m getting there slowly but surely. This framework certainly gives the impression of being built on some solid principles, even if I am having initial difficulty grokking those principles.

I’ll study those docs tomorrow I think. Thanks for your help and patience marc. It’s much appreciated!

Cheers,
Carl