Skip to content

Instantly share code, notes, and snippets.

@drnic
Created December 31, 2008 03:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drnic/41855 to your computer and use it in GitHub Desktop.
Save drnic/41855 to your computer and use it in GitHub Desktop.
The recipe object starts as an NSManagedObject for Recipe entity, but then becomes a Pointer without setValue:forKey: support
# Image well
def addImage(sender)
return unless recipe = recipeArrayController.selectedObjects.lastObject
p recipe # => #<NSManagedObject_Recipe_:0x800525ee0>
openPanel = NSOpenPanel.openPanel
openPanel.canChooseDirectories = false
openPanel.canCreateDirectories = false
openPanel.allowsMultipleSelection = false
selector = :"addImageSheetDidEnd:returnCode:contextInfo:"
openPanel.beginSheetForDirectory(nil, file: nil, modalForWindow: window, modalDelegate: self, didEndSelector: selector, contextInfo: recipe)
end
def addImageSheetDidEnd(openPanel, returnCode: returnCode, contextInfo: recipe)
return if returnCode == NSCancelButton
guid = NSProcessInfo.processInfo.globallyUniqueString
destPath = applicationSupportFolder.stringByAppendingPathComponent(guid)
NSFileManager.defaultManager.copyPath(openPanel.filename, toPath: destPath, handler: nil)
# recipe.imagePath = destPath # doesn't work?
p recipe # => #<Pointer:0x80065c1e0>
recipe.setValue(destPath, forKey:"imagePath")
# gives error:
# AppDelegate.rb:154:in `setValue:forKey:': NSUnknownKeyException: [<Pointer 0x80065c1e0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key imagePath. (RuntimeError)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment