Cocoa

Implementing [NSCell copyWithZone:] in Swift to Avoid Crashes in AppKit

Quick Summary If you add a Swift property to an NSTextFieldCell subclass and you may suddenly start getting random crashes! Implement an override of [NSCell copyWithZone:] that retains any properties to fix this: Gory Details... [read more]
Apple, Cocoa, Coding

WWDC 2015: Improving the Full Screen Window Experience

For the past 10 years I’ve given a talk at every Apple World Wild Developer Conference (WWDC). Well, except for one. That was 2007 when I was busy working on UIKit for the iPhone 1.0.... [read more]
Apple, Cocoa, Coding

NSTableView Tips: Doing Animations with Core Data

For my “Cyr Wheel Pattern Editor” app I am using CoreData and an NSTableView. However, I’m sort of “manually” doing bindings for the array content itself to get animations in the View Based NSTableView. Here’s... [read more]
Cocoa, Coding

NSTableView Tips: View Controller per row

Sometimes you may find your application has rather complex rows, and you want an NSViewController to manage each row in a “View Based” NSTableView. This is fairly easy to do, and I did it in... [read more]
Cocoa, Coding

NSTableView Tips: Not delaying the first responder

I have a little home-brew Cocoa app for making Cyr Wheel patterns. The UI is built with an NSTableView and looks like this: Now normally when you try to directly click on one of the... [read more]
Cocoa, Coding
no_thumbnail

Implementing delete in an NSTableView

I’ve seen many ways to implement delete in an NSTableView. Many are good. Many hardcode references to something they shouldn’t, and those are bad. Here’s an easy way: Subclass NSTableView and override keyDown: - (void)keyDown:(NSEvent... [read more]
Cocoa, Coding

Cocoa programmers: avoid writing to the user defaults when you don’t need to

[Edit: ecto ate this post, so I’m typing it in again!] I discovered that a lot of applications will unnecessarily write to NSUserDefaults. This causes your app to hit the disk when it shouldn’t, and... [read more]
Cocoa, Coding
no_thumbnail

Getting rid of the undo warning in Xcode after saving

One of the most annoying dialogs in Xcode is the undo warning dialog you get when attempting to undo after a save. I do this all the time, and I hate the warning. Luckily, there... [read more]
Cocoa, Coding

Wake up and smell the cocoa

Cocoa

Your most important breakpoint in Cocoa

…..drumroll please…and it is…is: objc_exception_throw. You should always have this breakpoint setup in any Cocoa or Cocoa Touch app that you are building. How do you do it? In Xcode, Run -> Show -> Breakpoints... [read more]
Cocoa, Coding

Xcode code completion and your code

How can you become a faster Cocoa programmer? One way is to adequately name your variables, enums and classes. Let’s start with enums and take an example from something new to NSTableView in Leopard. This... [read more]
Apple, Cocoa, Coding
no_thumbnail

Cocoa: willDisplayCell delegate method of NSTableView, [NSCell setTextColor], and “source lists”

Mac OS 10.5 added a “source list” highlighting style to NSTableView, with the API below for your reference: enum { NSTableViewSelectionHighlightStyleRegular = 0, NSTableViewSelectionHighlightStyleSourceList = 1, }; typedef NSInteger NSTableViewSelectionHighlightStyle; – (NSTableViewSelectionHighlightStyle)selectionHighlightStyle; – (void)setSelectionHighlightStyle:(NSTableViewSelectionHighlightStyle)selectionHighlightStyle; Source... [read more]
Apple, Cocoa, Coding
no_thumbnail

NSBrowser, bindings, and a custom cell class

Hi Cocoa Programmers, There is a small bug in NSBrowser if you use bindings and want a custom cell class. Typically, you would do something like this in your awakeFromNib: - (void)awakeFromNib { [iBrowser setCellClass:[ImageTextBrowserCell... [read more]
Apple, Cocoa, General
no_thumbnail

NSOutlineView: reloadData and crashes in reloadData

A note to NSOutlineView Cocoa programmers: It has never been safe to call reloadData while an outlineView is doing a reloadData. What the heck does that mean? Well, if you call reloadData, a whole bunch... [read more]
Apple, Cocoa, General
no_thumbnail

WWDC: Beyond Buttons and Sliders: Complex Controls in Cocoa

Come to WWDC this year! I’ll be giving a great talk on advanced control and cell creation with Cocoa: 120 Beyond Buttons and Sliders: Complex Controls in Cocoa Learn how you can quickly and efficiently... [read more]
Cocoa, General
no_thumbnail

Cocoa: modal NSColorPanel dialog.

Hi all, I’ve seen some people request how to do a modal color panel. Well, carbon has GetColor(..) which ultimately uses the same NSColorPanel. So, you can set it to begin a modal session before... [read more]
Apple, Cocoa, General
no_thumbnail

Xcode shortcuts to finding a file.

Cocoa Developers: While programming with Xcode, I’ve developed several habits to make me a faster programmer. I’ll share these tidbits with you. 1. Use Cmd-Shift-D to quickly open files that you know the names to.... [read more]
Apple, Cocoa, General
no_thumbnail

Cocoa: NSArrayController and two tableview’s

Hi Cocoa Developers, Tip of the day: Don’t bind two NSTableView’s to a single NSArrayController instance. Bugs will happen! More specifically, attempting to multi-select rows will not work properly — the two tableviews will fight... [read more]
Apple, Cocoa, General
no_thumbnail

Cocoa: Targeting the entire tableview in a drop operation

Hi Programmers. If you are doing drag and drop in an NSTableView with Cocoa, you can use the following method in your “validateDrop” datasource method to retarget the row it is going to: – (void)setDropRow:(int)row... [read more]
Apple, Cocoa, General
no_thumbnail

Cocoa: drop down menu buttons

In Cocoa, it is pretty easy to use an NSButton that creates a drop down menu. One of the key-tricks to making it appear to be an NSPopUpButton is to set the [NSCell sendActionOn:]. Generally,... [read more]
Apple, Cocoa, General
no_thumbnail

Cocoa: Creating a custom Color Picker in Cocoa. Part 1.

It is pretty easy to create a custom Color Picker that is available in any application, or for just your particular app. It isn’t difficult to do, but there are some caveats that you must... [read more]
Apple, Cocoa, General
no_thumbnail

Cocoa: Using NSPredicate and NSMetadataQuery

Hi Apple Cocoa developers. Here are some more tips and tricks for Cocoa development. On Tiger, there is a new class called NSMetadataQuery that allows you to do some cool Spotlight searches. See the “Spotlighter”... [read more]
Apple, Cocoa, General
no_thumbnail

Cocoa: Disappearing headers in CoreData generated TableViews

Apple Cocoa developers: Finally another blog entry for you! Everyone else: You may want to skip this one… It has come to my attention that some NSTableView instances created by dragging CoreData objects into Interface... [read more]
Apple, Cocoa, General
no_thumbnail

Cocoa only feed

One of the great things about WordPress is that you can subscribe to the feed that you are intersted in. For instance, if you just interested in Cocoa stuff, you can just watch this feed.... [read more]
Apple, Cocoa, General
no_thumbnail

Tiger and the dictionary is a keyboard shortcut away

A really cool “hidden” Tiger feature is the ability to quickly see the dictionary for (almost) any word in a Cocoa app. Move the cursor over a word, and press cmd-ctrl-d. You will see the... [read more]
Apple, General
no_thumbnail

Cmd – click. The subtle secret of Mac OS X.

It seems that a lot of people don’t know how cmd click works in a lot of Mac OS X Cocoa applications. To put it simply, Cmd-clicking on a non key window (or application for... [read more]
Cocoa, General
no_thumbnail

Drag and Drop in an NSTableView

Drag and Drop in an NSTableView is easy to do. However, I think the documentation (Table Views: Using Drag and Drop in Tables) for it isn’t particularly great. It misses a few points, so I’m... [read more]
Cocoa, General
no_thumbnail

Repost: How to find memory leaks in Cocoa apps with Object Alloc

(The original of this I accidentally killed — here is a copy). If your Cocoa application leaks memory, here is a way to find those leaks! 1) Open your application in Object Alloc 2) Start... [read more]
Apple, Cocoa, General

Subscribe to new posts:

You'll get an email whenever a I publish a new post to my blog and nothing more. -- Corbin

As an Amazon Associate I earn from qualifying purchases.

(c) 2008-2024 Corbin Dunn

Privacy Policy

Subscribe to RSS feeds for entries.

48 queries. 0.239 seconds.

Log in