NSData, NSImageView value binding, and NSUnarchiveFromData - nothing appears

  • 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.

    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?

    Note that I'm not using Core Data (upon which an overwhelming majority of value transformer docs seem to focus on.)  I'm working with nested NSDictionary structures.
  • On Jan 5, 2013, at 18:39, Matt DeLuco <matt...> 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.
previous month january 2013 next month
MTWTFSS
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
Go to today