调用接受可选错误指针的方法
我正在尝试调用 MacRuby 中定义如下的方法:
NSPropertyListSerialization
---------------------------
+ (id)propertyListWithStream:(NSInputStream *)stream
options:(NSPropertyListReadOptions)opt
format:(NSPropertyListFormat *)format
error:(NSError **)error
最后一个参数必须是指针,所以我这样做:
err = Pointer.new '@'
data = NSPropertyListSerialization.propertyListWithStream plist,
options: KCFPropertyListMutableContainers,
format: KCFPropertyListBinaryFormat_v1_0,
error: err
但是,我收到此错误:
expected instance of Pointer, got `200' (Fixnum) (TypeError)
堆栈跟踪来自 error: err
行。
无论对象的类型如何,作为错误
传递的错误都是相同的。它可以是 nil、指针、字符串或完全任意的类型,错误保持不变。
我不知道200
fixnum 来自哪里。当然不是我的代码(这个脚本中几乎没有比我粘贴的代码更多的代码)。
更新:在@whitequark和@alloy的帮助下解决了。这是为了在 iOS 模拟器中编辑 Safari 书签。您可以在此处查看如何读取/写入二进制plist文件
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
多行语句的堆栈跟踪始终引用最后一行(即,如果错误不是由可定位子表达式引起的),并且fixnum 200是以
KCFPropertyList
开头的常量之一。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
.根据 plist 的内容,您应该能够使用:
NSDictionary.dictionaryWithContentsOfFile(path)
来读取它。Depending on the contents of the plist, you should be able to read it with:
NSDictionary.dictionaryWithContentsOfFile(path)
.