Created
December 31, 2008 03:10
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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