Sorting a Table View of Core Data Records

October 8th, 2014

Filed under: Cocoa, Mac Development | 1 comment

In my previous post, I detailed the steps needed to bind a view-based table view to a Core Data entity. That post is missing one thing: sorting, which I’m going to cover now. Add an Ordering Attribute to the Entity Core Data does not have built-in support for sorting records. If you want a collection […]


Binding a View-Based Table View to a Core Data Entity

October 7th, 2014

Filed under: Cocoa, Mac Development | 3 comments

My main reason for writing this post is to have a reference for myself in case I need to bind a view-based table in the future. If this post helps anyone else, that’s a bonus. Set up the Array Controller The first step is to create an array controller and configure it to control a […]


Overriding NSDocument’s initWithType Method in Swift

September 22nd, 2014

Filed under: Cocoa | 2 comments

I struggled briefly with overriding NSDocument’s initWithType: method in Swift so I’m sharing my code. Hopefully this example will help others. convenience init(type typeName: String!, error outError: NSErrorPointer) { self.init() // Place your initialization code here. }


Swift: Go Through Array in Reverse Order

July 23rd, 2014

Filed under: Cocoa | Be the first to comment!

In Swift you would use the following for statement to go through each element in an array when you need to access the current index inside the for loop:  for index in 0..<listItems.count How do you go through the array in reverse order? Use the reverse keyword. for index in reverse(0..<listItems.count)


An Introduction to Swift Unit Testing

July 17th, 2014

Filed under: Cocoa, Xcode | 4 comments

This article shows you how to get started unit testing Swift code in Xcode with XCTest. If you’ve written Objective-C unit tests using XCTest or OCUnit, you should be able to smoothly transition to Swift after reading the article. But Objective-C unit testing experience isn’t required to read this article. Because Xcode 6 is currently […]


Creating a Save Panel Completion Handler with a Closure in Swift

July 15th, 2014

Filed under: Cocoa, Mac Development | Be the first to comment!

Swift is hot now. I figured I should share some of what I learned converting some Objective-C code to Swift. The Example The example in this article is a method to export data to a file. The example opens a save panel and calls the save panel’s completion handler. The completion handler checks if the […]


Loading Windows from Nib Files

March 18th, 2014

Filed under: Cocoa, Mac Development | Be the first to comment!

This post summarizes what I learned when I wrote some code to load a PDF preview window from an external nib file. I’m sharing what I learned in case someone else runs into problems loading windows from external nib/xib files. Short answer: NSWindowController is your friend. Call initWithWindowNibName: to load the window. Call showWindow: to […]


Create NSURL for Temporary File

December 3rd, 2013

Filed under: Cocoa, Mac Development | Be the first to comment!

I was recently working on some code that previews a PDF file. I had written a method to create the PDF that takes an NSURL object as an argument. I wanted to call that method to preview the PDF file, supplying an NSURL object for a temporary file. How do you create an NSURL object […]


CocoaPods

January 16th, 2013

Filed under: Cocoa, Mac Development | Be the first to comment!

I recently attended a Cocoaheads meeting where I was introduced to CocoaPods. Since many of the people who read this blog develop Mac and iOS software, I figured I should share what I learned. Keep in mind I haven’t used CocoaPods yet so I can’t answer any questions on the technical details. Go to the […]


Adding Items to NSTextView’s Contextual Menu

January 3rd, 2012

Filed under: Cocoa, Mac Development | 3 comments

When you add a text view to your application using Interface Builder you get access to the text view’s default contextual menu. You can open the contextual menu in your application by right-clicking (or control-clicking) in the text view. This menu lets you do things like cut, copy, paste, and check the document for spelling […]