Re: NSData, NSImageView value binding, and NSUnarchiveFromData - nothing appears
Re: NSData, NSImageView value binding, and NSUnarchiveFromData - nothing appears
- Subject: Re: NSData, NSImageView value binding, and NSUnarchiveFromData - nothing appears
- From: Quincey Morris <email@hidden>
- Date: Mon, 07 Jan 2013 14:47:38 -0800
On Jan 5, 2013, at 18:39, Matt DeLuco <email@hidden> wrote:
> When I started building my app I had been using NSImageView's Data binding to display image data in an NSData object, which is apparently deprecated.
>
> I read that a data transformer has to be used when using the NSImageView's Value binding. After digging around I realized that there's an NSUnarchiveFromData value transformer available. As far as I can tell, that should be sufficient to transform the bound NSData object into an NSImage suitable for the NSImageView.
Nope, image data isn't typically an archive at all -- it's TIFF data or PNG data or ... -- and so unarchiving isn't appropriate here.
> However, it doesn't seem to be working - nothing appears in the NSImageView in the UI. Using the same model key path in the NSImageView value binding works (but again, is deprecated.)
>
> What could I be missing? Is it that the NSUnarchiveFromData value transformer (as selected in XCode/IB under the NSImageView's value binding) is inappropriate; should I be coding my own value transformer?
Nope. Create a property in your data model (bound-to) object that returns a NSImage. This property should simply create the NSImage from the NSData you already have.
There would be two implementation considerations here:
1. For KVO compliance, if the NSData property could ever get a new value, you can make your NSImage property derived: write a +(NSSet*) keyPathsForValuesAffectingMyImageData that returns the property name of the NSData property.
2. Once you create the NSImage object, you should consider caching it in an instance variable, which then becomes something to be managed if the NSData changes.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden