Fire & Document Based Apps for Apple Platform

Can anyone help me with the correct process for taking the generated macOS project in Fire to being a document based app using storyboards please? I’ve gone round in circles trying to figure this out and not making much headway.

My only experience in doing this before Fire is in Xcode, where it generate all the basic artefacts needed for a document based app. As such there may be better way’s to think about this so happy to hear if so!

Thanks

Alan,

it should be pretty straight-forward and work basically the same as it would in an Xcode project — you’ll create a descendant from NSDocument where you implement the right methods to read/write your project, along with a view, and then all you need to do is register that in the Info.plist.

Examples from Fire itself:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

<plist version="1.0">
    <dict>
...
        <key>CFBundleDocumentTypes</key>
        <array>
            <dict>
                <key>CFBundleTypeExtensions</key>
                <array>
                    <string>sln</string>
                </array>
                <key>LSItemContentTypes</key>
                <array>
                    <string>com.remobjects.fire.sln</string>
                </array>
                <key>CFBundleTypeIconFile</key>
                <string>Project-Icon-White</string>
                <key>CFBundleTypeName</key>
                <string>Fire Solution</string>
                <key>CFBundleTypeRole</key>
                <string>Editor</string>
                <key>LSHandlerRank</key>
                <string>Owner</string>
                <key>LSTypeIsPackage</key>
                <integer>0</integer>
                <key>NSDocumentClass</key>
                <string>SolutionDocument</string>
            </dict>
...
``

where SolutionDocument is the NSDocument Descendant class I implemented, and where I overrode these two methods:

    public override bool writeToURL(NSURL! url) ofType(NSString! typeName) forSaveOperation(NSSaveOperationType saveOperation) originalContentsURL(NSURL absoluteOriginalContentsURL) error(ref NSError outError)
    public override bool readFromURL(NSURL! url) ofType(NSString! typeName) error(ref NSError outError)

as well
as

    public override void makeWindowControllers()
    {
        this.addWindowController(new SolutionDocumentWindowController withDocument(this));
    }

to create it's Window (snippets are C#, but same concepts apply in Oxygene or Silver).

I'll see if I can turn this into full sample project, next week

Thanks Marc, as always! Would be good to see an example that doesn’t use storyboards to achieve the document model Apple implement. Might help me piece together what’s going on under all these artefacts!

Lemme see if I can whip one up now. Whats your preferred language? I’ll start with that (and we’ll of course later convert it to all four).

Definitely swift for me please Marc!

1 Like

Documents.zip (438.9 KB)

How does this look for a start?

1 Like

Deleted my question as on reflection I didn’t think it was fair to ask you. One of my biggest challenges with the Apple ecosystem is it’s not transparent how much of the routing and behaviours happen in an app.

Trying to find out why now, in the example provided, we don’t get the click on window title to bring down the save as panel.

No, by all means, please ask — if I can help, I’ll be happy to, and it might benefit other readers, as well!

curious, yeah, I didn’t notice that. in Fire itself I get that for free w/o any manual code…

Found it!

In FooDocument.swift add this code:

override class var autosavesInPlace: Bool {
    return true
}

Interesting. I just came across that reviewing Fire as well, but thought, “na, that cant possibly influence that, can it…?” :wink:

Obscure eh? :slight_smile:

Updated the sample.

Indeed…

Final Sample is up, for all four languages, at https://github.com/remobjects/ElementsSamples/tree/master/Silver/Toffee/OS%20X/Documents (and the corresponding three other languages folders).

1 Like