Modifying Set via NSArrayController breaks Set in weird way
Modifying Set via NSArrayController breaks Set in weird way
- Subject: Modifying Set via NSArrayController breaks Set in weird way
- From: Etan Kissling <email@hidden>
- Date: Fri, 08 Jan 2016 15:14:56 +0000
- Thread-topic: Modifying Set via NSArrayController breaks Set in weird way
Got a strange issue here.
I have a small model class that stores a NSNumber.
@objc(Foo) final class Foo : NSObject {
dynamic var x = 0
override init() {
self.x = Int(arc4random())
}
init(x: Int) {
self.x = x
}
}
In my ViewController, there is a NSSet-based collection of such objects.
final class ViewController: NSViewController {
dynamic var foos: Set<Foo> = [Foo(x: 0), Foo(x: 1), Foo(x: 2)]
}
Then, I wire this Set to the Content Set binding of an NSArrayController.
When I launch the app and print the Set in the debugger, I get an expected output.
(lldb) e/x foos
(Set<SetCompare.Foo>) $R0 = {
[0] = 0x0000600000021080 {
ObjectiveC.NSObject = {
NSObject = {
isa = 0x041d800101268d11 NSKVONotifying_Foo
}
}
x = 0x0000000000000002
}
.........
}
Now, I modify the Set via the NSArraycontroller by adding or removing an object.
When I now print the Set, strange things happen:
(lldb) e/x foos
(Set<SetCompare.Foo>) $R1 = ([0] = <Execution was interrupted, reason: Attempted to dereference an invalid ObjC Object or send it an unrecognized selector.
The process has been returned to the state before expression evaluation.>, ............)
The set is still properly displayed, and strangely I can still print it from the app itself.
I can even create a copy of the set, that then displays like the first output again:
(lldb) e/x Set(foos.map { $0 })
(Set<SetCompare.Foo>) $R2 = {
[0] = 0x0000600000021080 {
ObjectiveC.NSObject = {
NSObject = {
isa = 0x051d800101268d11 NSKVONotifying_Foo
}
}
x = 0x0000000000000002
}
........
}
Unfortunately, stuff like querying the set (isSubsetOf), involving Foo's isEqual implementation is also broken now.
Can someone please explain what's going on here?
I've created a minimum sample project: https://scriptreactor.com/SetCompare.zip
Thanks
Etan
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden