View Full Version : Saving an Image Well File

Jun 28, 2011, 01:46 PM

I'm new to the board -- this is my first post. And I'm also a Cocoa newbie.

Thanks in advance for your patience :)

I'm writing an application that includes an image well that holds a background image. The application includes a feature that allows the user to change background images at will. And, since the image well is editable, the user can also drag an image in.

My question is this: If a user drags an image into the image well, how do I save it so that it can be reused in the future?

If you're able to help and since I'm so new this, please be as specific as possible in your explanation - I promise to pay it forward as quickly as possible ;)



Jun 28, 2011, 05:06 PM
The NSUserDefaults (http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSUserDefaults_Class) class will allow you to persist the chosen background. See User Defaults Programming Topics (http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/UserDefaults).

You can bind the NSImageView's value to the a key in the user's defaults. (XCode 4 instructions, XCode 3 should be similar)

Select the image well.
In the bindings inspector, under Value, tick bind to.
Choose Shared User Defaults Controller from the popup menu
Set the controller key to values
Set the model key path to backgroundImage (or whatever)
Set value transformer to NSKeyedUnarchiveFromData

Jun 28, 2011, 05:30 PM


Thank you so much!!