Posts

Post not yet marked as solved
0 Replies
640 Views
Some apps contain "Library files" like QuickLook generators or Spotlight importers, which are stored in locations such as theApp.app/Contents/Library/Spotlight/ or theApp.app/Contents/Library/QuickLook/, which essentially makes them available to the OS, as if they were installed in those Library subfolders. (e.g. OmniOutliner, OmniGraffle.)I want to similarly add a Quartz Filter to my MacOS app, which would otherwise go in Library/Filters, so that the app (at least) has access to that filter as if it were actually installed, rather than just having it as bundled 'content'.I can't see any specific method in Xcode's "Add Frameworks, Libraries and Embedded Content", and the "New Target" method of adding a Spotlgiht importer doesn't offer a generic Library item protocol. Does anyone know how it might be done?
Posted
by benwiggy.
Last updated
.
Post not yet marked as solved
4 Replies
1k Views
I've been trying to understand how to use Cocoa Bindings. There seems to be three ways: key-value observing; Notifications; and Bindings in Interface Builder.The purpose of bindings is supposedly to avoid writing lots of glue code and make it easy to transfer information between the model, the view and the controller -- but using Notifications and key-value observing seems to involve considerable amounts of code.Setting bindings in Interface Builder would seem to be the simplest way, though to me the most oblique. Could someone talk me through, or point me to some useful information about how to use this? Essentially, whenever the user triggers an IBAction, it has to do view things and document things. (e.g. get view status info; alter document; reset view)The View and Window objects only seems to offer Binding to the View Controller. So how do I bind the document to the View?I've looked at Apple's documentation, and the RayWenderlich site tutorials. Apart from a lack of code portability, is there really any reason why I shouldn't just define the relevant ViewController in the Document.swift file, and define the relevant Document in the ViewController.swift file, and then just call methods in each one?
Posted
by benwiggy.
Last updated
.
Post marked as solved
31 Replies
4.7k Views
I'm creating a MacOS document-based app in Swift. When running the app, if I make modifications to the document, and then select "Revert to Saved", I get a dialog asking me if I want to revert the document, losing current changes, but if I click on "Revert", nothing happens. The document keeps its changes.Furthermore, after clicking Revert, the document behaves as if there are no changes -- the titlebar icon is not grey; and the window closes without asking to save changes (I'm not using Autosave). It's like ChangeCount or isDocumentEdited have been reset.If I don't select Revert, then closing the document's window with unsaved changes brings a dialog asking to save.Apple's documentation for .revertToSaved reads as follows:The default implementation of this method presents an alert dialog giving the user the opportunity to cancel the operation. If the user chooses to continue, the method ensures that any editor registered using the Cocoa Bindings NSEditorRegistration informal protocol has discarded its changes and then invokes revert(toContentsOf:ofType:). If that returns false, the method presents the error to the user in an document-modal alert dialog.This suggests to me that it should work without needing to be overridden. Any idea why this is happening? Do I need to override the revert method to load the data back from disk? I've not yet sorted out Undo for the app, which might be relevant. But I am using ChangeCount to check whether edits have been made.
Posted
by benwiggy.
Last updated
.
Post marked as solved
15 Replies
5.3k Views
I have a document-based Cocoa MacOS Swift app, and I want to be able to Copy the document to the Pasteboard. The document is just represented by a document window: it's not text and there's nothing to 'select'. I've overridden the document's copy function, but the Copy menu item is still greyed out. I've ticked "Enabled" in the Attributes panel. How do I enable it and get the document's as its 'selected' object of operation?Thanks
Posted
by benwiggy.
Last updated
.
Post not yet marked as solved
3 Replies
692 Views
How do some apps manage to use Cut, Copy and Paste without affecting the contents of General Pasteboard? Presumably they're creating other instances of NSPasteboard using withUniqueName?If so, is it possible to find or list Pasteboard created?
Posted
by benwiggy.
Last updated
.
Post not yet marked as solved
6 Replies
1.8k Views
I've got a splitview with 3 columns, and I can adjust the position of one of the columns, but not the other one. I've no idea what I might have done to prevent this. I've tried changing the alignment things and deleting the constraints.I can delete the entire view and start again, but obviously I'd prefer not to.When the app is built, I can adjust the split to the correct size, so there's nothing preventing that. I can move the subviews themselves, or drag the entire view off, but the column just won't move.Probably something really basic, but it's driving me potty.
Posted
by benwiggy.
Last updated
.
Post not yet marked as solved
8 Replies
918 Views
I'm trying to write an app that will load MIDI files. I've written a Swfit script that works perfectly, but I'm having trouble with putting that into an app. override func read(from data: Data, ofType typeName: String) throws { let theMIDIPlayer = try AVMIDIPlayer.init(data: data, soundBankURL: nil) throw NSError(domain: NSOSStatusErrorDomain, code: unimpErr, userInfo: nil) }I'm getting a yellow warning that theMIDIPlayer was never initialized. Xcode made me put in the 'try': is that the reason? As a result, I can't use this in the ViewController, as it claims there's no such member of Document. override func viewDidAppear() { let document = self.view.window?.windowController?.document as! Document self.theView = document.theMIDIPlayer }Thanks.
Posted
by benwiggy.
Last updated
.
Post not yet marked as solved
2 Replies
727 Views
I see that NSDrawer has been deprecated. What are the alternatives? How are things like the side panels in Pages done?
Posted
by benwiggy.
Last updated
.
Post marked as solved
9 Replies
1.3k Views
I'm writing a MacOS app which loads PDFs as documents. I also want to save them. The app builds and works, but flags an error when I try to save or Save As. about not being able to save the file because it doesn't exist.Debug console gives the URL as something like:CGDataConsumerCreateWithFilename: failed to open `/Users/Ben/Library/Developer/Xcode/DerivedData/ReView-hitabkxsdoqaskfrelyidvcylvqs/Build/Products/Debug/file:/var/folders/qd/qjbz7jbn52938qrg166yn9l80000gn/T/TemporaryItems/(A%20Document%20Being%20Saved%20By%20ReView)/Test.pdf' for writing: No such file or directory.which looks very similar to what's described in this thread. https://forums.developer.apple.com/thread/120162My code is fairly minimal to start with: override func write(to url: URL, ofType typeName: String) throws { thePDFDocument?.write(toFile: url.absoluteString, withOptions: nil) }It was optimistic to think it would be that easy. What am I doing wrong?
Posted
by benwiggy.
Last updated
.