NSArrayController 通过 NSKeyedUnarchiveFromData 值转换器绑定到 NSUserDefaults
我有一个绑定到共享用户默认控制器的 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
)
那么我的配置有什么问题?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么空的 NSData 对象反序列化为空的 NSArray ?没有数据,因此解档器甚至不知道您的对象属于哪个类。如果您想取消归档一个空的
NSArray
,您必须先归档一个空的NSArray
。这不会导致空的NSData
。Why should an empty
NSData
object deserialize to an emptyNSArray
? There's no data, so the unarchiver can't even know which class your object has. If you want to unarchive an emptyNSArray
, you have to archive an emptyNSArray
first. This will not result in an emptyNSData
.问题的原因与此完全无关。事实证明我的配置没有问题。
谢谢你的时间,奥兹。
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.