0
我在覈心數據對象上使用@unionOfSets時遇到問題。核心數據和@unionOfSets
我有一個名爲列表的nsmanagedobject的子類。從列表到列表元素之間存在多對多關係。並且每個listElement與文件都有一對一的關係。
NSLog(@"%@", [NSApp valueForKeyPath:@"delegate.mainWindowController.sidebarViewController.arrayController.selection.list.listElement"]);
打印效果與預期
2010-03-24 18:11:15.844 Pirouette[7459:80f] Relationship objects for {(
<PRPlaylistElement: 0x10484c0> (entity: PRPlaylistElement; id: 0x10a71b0 <x-coredata://1EE9CEAD-E006-4487-8AA7-47764B87A91C/PRPlaylistElement/p108> ; data: <fault>),
<PRPlaylistElement: 0x1048a10> (entity: PRPlaylistElement; id: 0x10ac7d0 <x-coredata://1EE9CEAD-E006-4487-8AA7-47764B87A91C/PRPlaylistElement/p153> ; data: <fault>),
<PRPlaylistElement: 0x1048460> (entity: PRPlaylistElement; id: 0x10acf60 <x-coredata://1EE9CEAD-E006-4487-8AA7-47764B87A91C/PRPlaylistElement/p157> ; data: <fault>),
<PRPlaylistElement: 0x1047c60> (entity: PRPlaylistElement; id: 0x10a6850 <x-coredata://1EE9CEAD-E006-4487-8AA7-47764B87A91C/PRPlaylistElement/p105> ; data: <fault>)
然而,當我試圖讓一組文件的每個listElements的設定listElements的。
NSLog(@"%@", [NSApp valueForKeyPath:@"delegate.mainWindowController.si[email protected]unionOfSets.file"]);
我收到以下錯誤
2010-03-24 18:41:20.075 Pirouette[7616:80f] An uncaught exception was raised
2010-03-24 18:41:20.082 Pirouette[7616:80f] [<NSCFSet 0x1056e90> valueForKeyPath:]: this class does not implement the unionOfSets operation.
2010-03-24 18:41:20.086 Pirouette[7616:80f] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '[<NSCFSet 0x1056e90> valueForKeyPath:]: this class does not implement the unionOfSets operation.'
困惑,因爲我認爲,很多核心數據關係是NSSets。
也要注意
NSLog(@"%@", [NSApp valueForKeyPath:@"delegate.mainWindowController.sidebarViewController.arrayController.selection.list.listElement.file"]);
提供了以下
2010-03-24 18:16:45.843 Pirouette[7505:80f] {(
<PRSong: 0x10a9c10> (entity: PRSong; id: 0x104a8d0 <x-coredata://1EE9CEAD-E006-4487-8AA7-47764B87A91C/PRSong/p123> ; data: <fault>),
<PRSong: 0x10a00f0> (entity: PRSong; id: 0x1049b20 <x-coredata://1EE9CEAD-E006-4487-8AA7-47764B87A91C/PRSong/p128> ; data: <fault>),
<PRSong: 0x10ac480> (entity: PRSong; id: 0x10476a0 <x-coredata://1EE9CEAD-E006-4487-8AA7-47764B87A91C/PRSong/p145> ; data: <fault>),
<PRSong: 0x1099cd0> (entity: PRSong; id: 0x104a380 <x-coredata://1EE9CEAD-E006-4487-8AA7-47764B87A91C/PRSong/p120> ; data: <fault>))}
然而
由於某種原因,我不能綁定一個NSArrayController的的contentSet它。
KevinD:「我很困惑,因爲我認爲 - 核心數據中的許多關係都是NSSets。」他們是。這就是爲什麼你的日誌輸出將「NSCFSet」作爲'valueForKeyPath:'消息的接收者的原因。正如Chuck所說的,你要求這個集合用於數組操作,所以set-does-not-support-array-operations異常就是你所得到的。 – 2010-03-25 02:14:55
我在問題中沒有看到「@ unionOfArrays」(已編輯?!)。無論如何,'@ unionOf..'操作符在數組上運行。如果您需要在一個集合上使用這些運算符,請使用'@distinctUnionOf ...'變體。 – 2010-03-25 06:40:40