Calling a method that accepts an optional error pointer
I'm trying to call a method in MacRuby that's defined like this:
NSPropertyListSerialization
---------------------------
+ (id)propertyListWithStream:(NSInputStream *)stream
options:(NSPropertyListReadOptions)opt
format:(NSPropertyListFormat *)format
error:(NSError **)error
The last argument has to be a pointer, so I'm doing this:
err = Pointer.new '@'
data = NSPropertyListSerialization.propertyListWithStream plist,
options: KCFPropertyListMutableContainers,
format: KCFPropertyListBinaryFormat_v1_0,
error: err
开发者_StackOverflow
However, I get this error:
expected instance of Pointer, got `200' (Fixnum) (TypeError)
The stack trace comes from the error: err
line.
This error is the same regardless of the type of the object passed as error
. It can be nil, a Pointer, a string or a completely arbitrary type, the error stays the same.
I have no idea where 200
fixnum comes from. Certainly not my code (there is barely any more code in this script than what I pasted).
Update: Solved with the help of @whitequark and @alloy. This was for editing Safari bookmarks in iOS Simulator. You can see how to read/write binary plist files here
Stacktraces for multiline statements always refer to the last line (i.e. if the error is not caused by a locateable subexpression), and fixnum 200 is one of the constants beginning with KCFPropertyList
.
Depending on the contents of the plist, you should be able to read it with: NSDictionary.dictionaryWithContentsOfFile(path)
.
精彩评论