Skip to main content

Posts

Showing posts from September, 2016

My Favourite macOS Development Bugs

1. Changing the Background Colour A simple thing to do in iOS is to change the background colour of a view but in macOS you need to first tell the view you want the layer and then reference the layer. And finally you need to pass it a CGColor rather than an NSColor. 2. NSTextView NSTextView and the way it interacts with NSScrollView is a whole can of worms that I'm working on getting my head around. But one of the first hurdles is that if you are working with the component parts: NSLayoutManager, NSTextContainer and NSTextStorage – then you must retain a reference to the text store for it to work as expected. Follow @sketchytech

Taming NSDocument and Understanding Who's Boss: Creating a Simple macOS Text Editor (Swift 3, Xcode 8 beta 6)

Looking at Apple's diagrams in their documentation we see that NSDocumentController is boss of NSDocument, which in turn is boss of NSWindowController and this leads to the document window being displayed. Yup, but what is really happening and what does this mean in terms of code? Creating the project As with other apps, create a new project and select macOS Cocoa as the type: And having clicked next, make sure you select the "Create Document-Based Application" checkbox: Navigating the Files When a document-based app is created alongside the familiar AppDelegate and ViewController files we have Document.swift as well. This final class file providing a subclass of NSDocument. The most important thing to note first of all is that: the ViewController class does not own or create an instance of our NSDocument subclass (i.e. Document) the Document class does not own or create an instance of the NSViewController subclass (i.e. ViewController) So h