Kodeco Forums

Cocoa Bindings on OS X Tutorial

Cocoa bindings make glue code a thing of the past. Discover how you can simplify your controller code in this Cocoa Bindings on OS X Tutorial!


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/1150-cocoa-bindings-on-os-x-tutorial

Nice tutorial, thanks. I’m really hoping there a followup imminently coming which will show how to incorporate NSUndoManager into bindings, and especially how to tie Core Data into this.

Great tutorial, thanks! :slight_smile:
Do you have any knowledge about any OS X books being developed by Raywenderlich.com team?

Great tutorial! I did find a minor error under “Binding Text Fields to Their Properties”. Where you write “The Controller Key should be objectValue.trackName.” I think Controller Key should be Model Key Path. That tripped me up for a bit.

Really enjoyed this tutorial. Thanks for posting.

Thanks for catching that, the tutorial has been updated.

Great tutorial! Thanks a lot!

May I ask a question that why there’s self.willChangeValueForKey and self.didChangeValueForKey for screenShots but no such pieces of code for artworkImage?

When should I use these code in binding?

Any reply will be huge appreciate.

In general, you should use will/didChangeValueForKey if you are going to affect a value in-directly, for example if you have a Class Student and it has firstName, lastName and fullName where fullName is getting and setting in firstName and lastName, then on changing firstName or lastName you should call will/didChangeValueForKey fullName

Great cocoa binding article Jake. Been using it for a couple of years. you can also use binding in a more dynamic way duplicate-free views also using DryView: here it is and a sample project using it Reusable XIBs in cocoa binding (DRY Views) NSView, Part 2 – AMTourky

It seems that the sources of this tutorial won’t build anymore. I’ll be glad to get an update ! And many thanks for all your work !

Great tutorial on Cocoa bindings

To get this working with Xcode 8 and Swift 3, I made the following changes after accepting defaults of the automatic conversion process and applying the suggested project changes etc.

  1. iTunesResults.swift
    Line 36, changed to
    dynamic var artworkURL : URL!

  2. iTunesRequestManager.swift
    Line 39, changed to
    let itunesData : [String : Any] = try JSONSerialization.jsonObject(with: data!, options: .allowFragments) as! [String : Any]