-
NSLayoutManager.setTemporaryAttributes(:forCharacterRange:)
is far faster thanNSTextStorage.setAttributes(:range:)
. On My iMac, former took about 2 seconds, and latter took about 17 seconds in optimised build of test suit. -
Anyway, modifying
NSTextStorage
also took 2 seconds when wrapped bybeginEditing
/endEditing
pair. So this performance drop is mainly due to inefficient layout refresh. You will get same performance if you can suppress the layout refreshes.
- You should not kill the window object while
func windowWillClose(notification: NSNotification)
is being called. It will cause program crash. Just keep it alive. You can try to remove some subviews from it to clean up stuffs.
-
If you want a cell (including view-based table-view,
NSTableCellView
in view-based table-view) to be edited with a small delay after selecting it (just like you're renaming a file in Finder), use this code.outlineView.doubleAction = "dummyDoubleAction:"
This makes the table-view to wait for double-clicking timing, and the small delay will be introduced effectively.
-
If you want to get notified when the node label editing starts, see here.
-
NSTableView.sizeLastColumnToFit
doesn seem to work if there's no row. Try applying this after you add some row.
-
How to clear focus ring?
let tf = getTextField() as NSTextField tf.window!.makeFirstResponder(nil)
-
How to clear focus ring with Escape key?
@objc override func cancelOperation(sender: AnyObject?) { self.window!.makeFirstResponder(nil) }
OS X provides a lot of default icons. These icons are accessible via several methods.
Here're related informations.
-
http://stackoverflow.com/questions/1381915/how-do-i-get-the-icon-of-the-users-mac
-
Apple provided "IconCollection" example. Newer, but contains only small number of icons.
-
Another system icon viewer example. Old, but provides far more constants.
Note that drag-drop support could be overriden and can be different by view classes.
For example, NSOutlineView
uses completely different approach to support per-item drag-and-drop.
-
NSOutlineView
You should start with implementing this data-source method at first.
@objc func outlineView(outlineView: NSOutlineView, pasteboardWriterForItem item: AnyObject?) -> NSPasteboardWriting! { let m = NSPasteboardItem() return m }
You'll see the outlne-view will drag nodes immediately. Now start to add extra supports.