Re: Modifying Set via NSArrayController breaks Set in weird way
Re: Modifying Set via NSArrayController breaks Set in weird way
- Subject: Re: Modifying Set via NSArrayController breaks Set in weird way
- From: Etan Kissling <email@hidden>
- Date: Fri, 08 Jan 2016 21:44:01 +0000
- Thread-topic: Modifying Set via NSArrayController breaks Set in weird way
Wow, thanks for the various hints.
a. Could be :-) However, since the Find feature of the minimal app stops working properly after modifying the collection, there's definitely something fishy.
b. Yep, the dynamic keyword can afaik only be applied to types that are representable in objc.
c. Hm. Not sure. == on NSObject subclasses is broken. See https://lists.swift.org/pipermail/swift-users/Week-of-Mon-20151214/000515.html
d. THANKS ! <3 That's it!
Swift's hashValue probably forwards to ObjC's hash, but not vice versa. That's why it breaks in a strange way when I only override Swift's hashValue.
As soon as the set is bridged to ObjC, the default hash is used and not my customized one.
Etan
On 08 Jan 2016, at 20:24, Quincey Morris <email@hidden<mailto:email@hidden>> wrote:
On Jan 8, 2016, at 09:59 , Etan Kissling <email@hidden<mailto:email@hidden>> wrote:
As the comments in the sample project describe in the introductory comments,
modifying the code to force an NSSet does not solve the problem.
a. I believe your debugger display problems are just that — problems in the debugger, not necessarily anything to do with your code (though certainly getting in the way). I’ve seen other cases where the debugger generates huge output (many megabytes of text) and ties Xcode up for 20 minutes or more while doing it.
b. With your original Set<Foo> code, the set does indeed change from a Swift internal implementation to a _XXX_NSSet implementation after you add an entry via the array controller, though this is probably irrelevant.
c. With your Set<Foo> code, you should probably be using ==, not isEqual, even though the Foos are NSObjects.
d. For NSObject equality, the hash getter method is called ‘hash’, not ‘hashValue’.
I don’t know offhand if Swift tries to bridge between ‘hash’ and ‘hashValue’ under any circumstances. (It seems like it must, otherwise I don’t see how Set and Set<> could bridge properly, but I admit I haven’t taken the time to try to think this through.) However, I suspect that your immediate problems are cause by the lack of a ‘hash’ method. Certainly, when I changed the Set<Foo> variable to NSMutableSet, your hashValue method wasn’t ever called.
_______________________________________________
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