NSArrayController 通过 NSKeyedUnarchiveFromData 值转换器绑定到 NSUserDefaults

发布于 2024-11-19 20:00:52 字数 4469 浏览 7 评论 0原文

我有一个绑定到共享用户默认控制器的 NSArrayController 实例。 (见下面的截图)关键路径指向 NSData 的一个实例,当解压时应该给出一个数组。但是当笔尖开始加载时,它给出 -

2011-07-10 23:55:23.093 MyApp[18139:507] -[__NSCFConstantString characterAtIndex:]: Range or index out of bounds
2011-07-10 23:55:23.106 MyApp[18139:507] (
    0   CoreFoundation                      0x00007fff95729986 __exceptionPreprocess + 198
    1   libobjc.A.dylib                     0x00007fff90d5dd5e objc_exception_throw + 43
    2   CoreFoundation                      0x00007fff957297ba +[NSException raise:format:arguments:] + 106
    3   CoreFoundation                      0x00007fff95729744 +[NSException raise:format:] + 116
    4   CoreFoundation                      0x00007fff956e750e -[__NSCFString characterAtIndex:] + 94
    5   Foundation                          0x00007fff94c090a7 NSKeyValuePropertyForIsaAndKeyPathInner + 109
    6   Foundation                          0x00007fff94c08d43 NSKeyValuePropertyForIsaAndKeyPath + 159
    7   Foundation                          0x00007fff94c08afb -[NSObject(NSKeyValueObserverRegistration) addObserver:forKeyPath:options:context:] + 82
    8   Foundation                          0x00007fff94c3f5a0 -[NSKeyValueNestedProperty object:didAddObservance:recurse:] + 222
    9   Foundation                          0x00007fff94c0a177 -[NSObject(NSKeyValueObserverRegistration) _addObserver:forProperty:options:context:] + 481
    10  Foundation                          0x00007fff94c08b18 -[NSObject(NSKeyValueObserverRegistration) addObserver:forKeyPath:options:context:] + 111
    11  AppKit                              0x00007fff95beddd1 -[NSAutounbinder addObserver:forKeyPath:options:context:] + 210
    12  AppKit                              0x00007fff95a1e323 -[NSBinder _updateObservingRegistration:] + 859
    13  AppKit                              0x00007fff95a1d4a1 -[NSBinder establishConnection] + 314
    14  AppKit                              0x00007fff95a1185b -[NSObject(NSKeyValueBindingCreation) bind:toObject:withKeyPath:options:] + 591
    15  AppKit                              0x00007fff95a0ab81 -[NSIBObjectData nibInstantiateWithOwner:topLevelObjects:] + 1079
    16  AppKit                              0x00007fff95a011b9 loadNib + 322
    17  AppKit                              0x00007fff95a006b6 +[NSBundle(NSNibLoading) _loadNibFile:nameTable:withZone:ownerBundle:] + 217
    18  AppKit                              0x00007fff95a005d1 +[NSBundle(NSNibLoading) loadNibFile:externalNameTable:withZone:] + 141
    19  AppKit                              0x00007fff95bee328 -[NSWindowController loadWindow] + 221
    20  AppKit                              0x00007fff95bee0e3 -[NSWindowController window] + 75
    21  AppKit                              0x00007fff95bedf51 -[NSWindowController showWindow:] + 40
    22  MyApp                               0x00000001000024af -[MyAppDelegate showPreferencesWindow:] + 255
    23  MyApp                               0x0000000100005229 -[TBStatusWindowController preferences:] + 89
    24  CoreFoundation                      0x00007fff9571911d -[NSObject performSelector:withObject:] + 61
    25  AppKit                              0x00007fff95afd852 -[NSApplication sendAction:to:from:] + 139
    26  AppKit                              0x00007fff95afd784 -[NSControl sendAction:to:] + 88
    27  AppKit                              0x00007fff95afd6af -[NSCell _sendActionFrom:] + 137
    28  AppKit                              0x00007fff95afcb7a -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2014
    29  AppKit                              0x00007fff95b7c57c -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 489
    30  AppKit                              0x00007fff95afb786 -[NSControl mouseDown:] + 786
    31  AppKit                              0x00007fff95ac666e -[NSWindow sendEvent:] + 6280
    32  AppKit                              0x00007fff95a5ef19 -[NSApplication sendEvent:] + 5665
    33  AppKit                              0x00007fff959f542b -[NSApplication run] + 548
    34  AppKit                              0x00007fff95c7352a NSApplicationMain + 867
    35  MyApp                               0x0000000100001a40 main + 32
    36  MyApp                               0x0000000100001a14 start + 52
)

那么我的配置有什么问题?

绑定 NSArrayController

I have an NSArrayController instance bound to Shared User Defaults Controller. (see screenshot below) The key path points to an instance of NSData, when unarchived should give an array. But when the nib starts to load, it gives -

2011-07-10 23:55:23.093 MyApp[18139:507] -[__NSCFConstantString characterAtIndex:]: Range or index out of bounds
2011-07-10 23:55:23.106 MyApp[18139:507] (
    0   CoreFoundation                      0x00007fff95729986 __exceptionPreprocess + 198
    1   libobjc.A.dylib                     0x00007fff90d5dd5e objc_exception_throw + 43
    2   CoreFoundation                      0x00007fff957297ba +[NSException raise:format:arguments:] + 106
    3   CoreFoundation                      0x00007fff95729744 +[NSException raise:format:] + 116
    4   CoreFoundation                      0x00007fff956e750e -[__NSCFString characterAtIndex:] + 94
    5   Foundation                          0x00007fff94c090a7 NSKeyValuePropertyForIsaAndKeyPathInner + 109
    6   Foundation                          0x00007fff94c08d43 NSKeyValuePropertyForIsaAndKeyPath + 159
    7   Foundation                          0x00007fff94c08afb -[NSObject(NSKeyValueObserverRegistration) addObserver:forKeyPath:options:context:] + 82
    8   Foundation                          0x00007fff94c3f5a0 -[NSKeyValueNestedProperty object:didAddObservance:recurse:] + 222
    9   Foundation                          0x00007fff94c0a177 -[NSObject(NSKeyValueObserverRegistration) _addObserver:forProperty:options:context:] + 481
    10  Foundation                          0x00007fff94c08b18 -[NSObject(NSKeyValueObserverRegistration) addObserver:forKeyPath:options:context:] + 111
    11  AppKit                              0x00007fff95beddd1 -[NSAutounbinder addObserver:forKeyPath:options:context:] + 210
    12  AppKit                              0x00007fff95a1e323 -[NSBinder _updateObservingRegistration:] + 859
    13  AppKit                              0x00007fff95a1d4a1 -[NSBinder establishConnection] + 314
    14  AppKit                              0x00007fff95a1185b -[NSObject(NSKeyValueBindingCreation) bind:toObject:withKeyPath:options:] + 591
    15  AppKit                              0x00007fff95a0ab81 -[NSIBObjectData nibInstantiateWithOwner:topLevelObjects:] + 1079
    16  AppKit                              0x00007fff95a011b9 loadNib + 322
    17  AppKit                              0x00007fff95a006b6 +[NSBundle(NSNibLoading) _loadNibFile:nameTable:withZone:ownerBundle:] + 217
    18  AppKit                              0x00007fff95a005d1 +[NSBundle(NSNibLoading) loadNibFile:externalNameTable:withZone:] + 141
    19  AppKit                              0x00007fff95bee328 -[NSWindowController loadWindow] + 221
    20  AppKit                              0x00007fff95bee0e3 -[NSWindowController window] + 75
    21  AppKit                              0x00007fff95bedf51 -[NSWindowController showWindow:] + 40
    22  MyApp                               0x00000001000024af -[MyAppDelegate showPreferencesWindow:] + 255
    23  MyApp                               0x0000000100005229 -[TBStatusWindowController preferences:] + 89
    24  CoreFoundation                      0x00007fff9571911d -[NSObject performSelector:withObject:] + 61
    25  AppKit                              0x00007fff95afd852 -[NSApplication sendAction:to:from:] + 139
    26  AppKit                              0x00007fff95afd784 -[NSControl sendAction:to:] + 88
    27  AppKit                              0x00007fff95afd6af -[NSCell _sendActionFrom:] + 137
    28  AppKit                              0x00007fff95afcb7a -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2014
    29  AppKit                              0x00007fff95b7c57c -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 489
    30  AppKit                              0x00007fff95afb786 -[NSControl mouseDown:] + 786
    31  AppKit                              0x00007fff95ac666e -[NSWindow sendEvent:] + 6280
    32  AppKit                              0x00007fff95a5ef19 -[NSApplication sendEvent:] + 5665
    33  AppKit                              0x00007fff959f542b -[NSApplication run] + 548
    34  AppKit                              0x00007fff95c7352a NSApplicationMain + 867
    35  MyApp                               0x0000000100001a40 main + 32
    36  MyApp                               0x0000000100001a14 start + 52
)

So what is the problem with my configuration?

Bindings
NSArrayController

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

沉睡月亮 2024-11-26 20:00:52

为什么空的 NSData 对象反序列化为空的 NSArray ?没有数据,因此解档器甚至不知道您的对象属于哪个类。如果您想取消归档一个空的 NSArray,您必须先归档一个空的 NSArray。这不会导致空的 NSData

Why should an empty NSData object deserialize to an empty NSArray? There's no data, so the unarchiver can't even know which class your object has. If you want to unarchive an empty NSArray, you have to archive an empty NSArray first. This will not result in an empty NSData.

他是夢罘是命 2024-11-26 20:00:52

问题的原因与此完全无关。事实证明我的配置没有问题。

谢谢你的时间,奥兹。

The reason for the problem is totally unrelated to this one. It turns out that there is nothing wrong with my configuration.

Thanks for your time, omz.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文