Nil items in NSMutableSet
Hello All, I am using NSMutableSet quite extensively in my app mostly just adding items to it and reading them (almost never removing). However sometimes it crashes under very interesting conditions. I can't reliable recreate the issue but sometimes I get a 'attempted to insert nil' exception when FILTERING the set using a predicate, if I breakpoint at this exception and print the set description I see that it has many valid objects but also a bunch of nil (null) objects which doesn't make any sense since I can't insert nil objects to the set in the first place! I can't think of any scenario where I can insert nil objects to the set or insert a valid object which would then point nil. My app is multi-threaded and the set is accessed in @sychronized blocks from many threads all the time. Has anyone had a similar problem? am I missing something? is it a bug with the foundation object? Thanks for any insight. Regards, Alejandro Rodríguez___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Nil items in NSMutableSet
On Tue, Mar 16, 2010 at 10:28 AM, Alejandro Rodriguez l.mephi...@gmail.com wrote: Hello All, I am using NSMutableSet quite extensively in my app mostly just adding items to it and reading them (almost never removing). However sometimes it crashes under very interesting conditions. I can't reliable recreate the issue but sometimes I get a 'attempted to insert nil' exception when FILTERING the set using a predicate, if I breakpoint at this exception and print the set description I see that it has many valid objects but also a bunch of nil (null) objects which doesn't make any sense since I can't insert nil objects to the set in the first place! I can't think of any scenario where I can insert nil objects to the set or insert a valid object which would then point nil. My app is multi-threaded and the set is accessed in @sychronized blocks from many threads all the time. Has anyone had a similar problem? am I missing something? is it a bug with the foundation object? What kind of objects are in the set? What do their -isEqual: and -hash methods look like? Is there any possibility that objects in that set are changed in a way that affects the results returned by their -isEqual: and/or -hash methods? -- Clark S. Cox III clarkc...@gmail.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Nil items in NSMutableSet
Hello Clark, The objects in the set are NSObject subclasses that have a NSString readonly property (messageId) and are always initialized through initWithMessageId: where that value is set and never changed. The hash and isEqual methods are as follows: - (NSUInteger)hash{ return (messageId == nil) ? [super hash]:[messageId hash]; } - (BOOL)isEqual:(id)object{ if([self messageId] == nil)return [super isEqual:object]; if([object isKindOfClass:[RTMessage class]]){ return [[self messageId] isEqualToString:[object messageId]]; } if([object isKindOfClass:[NSString class]]){ return [[self messageId] isEqualToString:object]; } return [super isEqual:object]; } This basically allows me to do something like [messageSet member:@123] and return the object with ID 123 or [memberSet member:messageObject] and have the same result. This is the first condition I checked when the problem started presenting itself but since messageId is readonly and retained then it shouldn't ever change through the lifetime of the object once created and added to the set. This is the condition that the docs say must be ensured. Thanks for your response, Alejandro Rodríguez On Mar 16, 2010, at 1:46 PM, Clark Cox wrote: On Tue, Mar 16, 2010 at 10:28 AM, Alejandro Rodriguez l.mephi...@gmail.com wrote: Hello All, I am using NSMutableSet quite extensively in my app mostly just adding items to it and reading them (almost never removing). However sometimes it crashes under very interesting conditions. I can't reliable recreate the issue but sometimes I get a 'attempted to insert nil' exception when FILTERING the set using a predicate, if I breakpoint at this exception and print the set description I see that it has many valid objects but also a bunch of nil (null) objects which doesn't make any sense since I can't insert nil objects to the set in the first place! I can't think of any scenario where I can insert nil objects to the set or insert a valid object which would then point nil. My app is multi-threaded and the set is accessed in @sychronized blocks from many threads all the time. Has anyone had a similar problem? am I missing something? is it a bug with the foundation object? What kind of objects are in the set? What do their -isEqual: and -hash methods look like? Is there any possibility that objects in that set are changed in a way that affects the results returned by their -isEqual: and/or -hash methods? -- Clark S. Cox III clarkc...@gmail.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Nil items in NSMutableSet
On Tue, Mar 16, 2010 at 11:06 AM, Alejandro Rodriguez l.mephi...@gmail.com wrote: Hello Clark, The objects in the set are NSObject subclasses that have a NSString readonly property (messageId) and are always initialized through initWithMessageId: where that value is set and never changed. The hash and isEqual methods are as follows: - (NSUInteger)hash{ return (messageId == nil) ? [super hash]:[messageId hash]; } - (BOOL)isEqual:(id)object{ if([self messageId] == nil)return [super isEqual:object]; if([object isKindOfClass:[RTMessage class]]){ return [[self messageId] isEqualToString:[object messageId]]; } if([object isKindOfClass:[NSString class]]){ return [[self messageId] isEqualToString:object]; } return [super isEqual:object]; } This basically allows me to do something like [messageSet member:@123] and return the object with ID 123 or [memberSet member:messageObject] and have the same result. Your code doesn't account for the possibility that the order of comparison might happen in the other order (i.e. [@123 isEqual: object]). I wouldn't be surprised if NSSet is assuming that equality is transitive (i.e. [a isEqual: b] == [b isEqual: a]). This is the first condition I checked when the problem started presenting itself but since messageId is readonly and retained Is it retain or copy? It really should be the latter. If there's any chance that the object is ever initialized with an NSMutableString the difference is important. then it shouldn't ever change through the lifetime of the object once created and added to the set. This is the condition that the docs say must be ensured. Thanks for your response, Alejandro Rodríguez On Mar 16, 2010, at 1:46 PM, Clark Cox wrote: On Tue, Mar 16, 2010 at 10:28 AM, Alejandro Rodriguez l.mephi...@gmail.com wrote: Hello All, I am using NSMutableSet quite extensively in my app mostly just adding items to it and reading them (almost never removing). However sometimes it crashes under very interesting conditions. I can't reliable recreate the issue but sometimes I get a 'attempted to insert nil' exception when FILTERING the set using a predicate, if I breakpoint at this exception and print the set description I see that it has many valid objects but also a bunch of nil (null) objects which doesn't make any sense since I can't insert nil objects to the set in the first place! I can't think of any scenario where I can insert nil objects to the set or insert a valid object which would then point nil. My app is multi-threaded and the set is accessed in @sychronized blocks from many threads all the time. Has anyone had a similar problem? am I missing something? is it a bug with the foundation object? What kind of objects are in the set? What do their -isEqual: and -hash methods look like? Is there any possibility that objects in that set are changed in a way that affects the results returned by their -isEqual: and/or -hash methods? -- Clark S. Cox III clarkc...@gmail.com -- Clark S. Cox III clarkc...@gmail.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Nil items in NSMutableSet
Your code doesn't account for the possibility that the order of comparison might happen in the other order (i.e. [@123 isEqual: object]). I wouldn't be surprised if NSSet is assuming that equality is transitive (i.e. [a isEqual: b] == [b isEqual: a]). For reference, this property is not transitivity, the transitivity relation is: a - b ^ b - c = a - c (for some relation -) The one you're looking for is commutativity. Bob___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Nil items in NSMutableSet
On Tue, Mar 16, 2010 at 11:35 AM, Thomas Davie tom.da...@gmail.com wrote: Your code doesn't account for the possibility that the order of comparison might happen in the other order (i.e. [@123 isEqual: object]). I wouldn't be surprised if NSSet is assuming that equality is transitive (i.e. [a isEqual: b] == [b isEqual: a]). For reference, this property is not transitivity, the transitivity relation is: a - b ^ b - c = a - c (for some relation -) The one you're looking for is commutativity. Indeed; must have been echos of my previous life as a C++ programmer creeping into the Obj-C part of my brain (in C++, the std::set class uses less than, instead of equality, where transitivity is the important property, not commutativity). :) -- Clark S. Cox III clarkc...@gmail.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Nil items in NSMutableSet
Thats a very interesting take on the problem. I'm going to look into that. Make sure that isEqual: returns the same both ways. Thanks and I'll let you know how it goes. I can't really reproduce the issue so I won't know if it's fixe but at least I'll test the commutativity of the comparison. Cheers, Alejandro On Mar 16, 2010, at 2:45 PM, Clark Cox wrote: On Tue, Mar 16, 2010 at 11:35 AM, Thomas Davie tom.da...@gmail.com wrote: Your code doesn't account for the possibility that the order of comparison might happen in the other order (i.e. [@123 isEqual: object]). I wouldn't be surprised if NSSet is assuming that equality is transitive (i.e. [a isEqual: b] == [b isEqual: a]). For reference, this property is not transitivity, the transitivity relation is: a - b ^ b - c = a - c (for some relation -) The one you're looking for is commutativity. Indeed; must have been echos of my previous life as a C++ programmer creeping into the Obj-C part of my brain (in C++, the std::set class uses less than, instead of equality, where transitivity is the important property, not commutativity). :) -- Clark S. Cox III clarkc...@gmail.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Nil items in NSMutableSet
You were right, my equality is not transitive. id ob = [[objectClass alloc] initWithId:@hello]; [ob isEqual:@hello]; //returns YES [@hello isEqual:ob]; //returns NO That may very well be the problem... now... I have no idea on how I will make the second test return YES. doesn't that depend on the implementation of isEqual of the asking object in this case NSString? Have any of you had to deal with this before? I'll dive into the docs and see what details I find that might be useful. Seems we are getting somewhere cheers! Alejandro On Mar 16, 2010, at 2:45 PM, Clark Cox wrote: On Tue, Mar 16, 2010 at 11:35 AM, Thomas Davie tom.da...@gmail.com wrote: Your code doesn't account for the possibility that the order of comparison might happen in the other order (i.e. [@123 isEqual: object]). I wouldn't be surprised if NSSet is assuming that equality is transitive (i.e. [a isEqual: b] == [b isEqual: a]). For reference, this property is not transitivity, the transitivity relation is: a - b ^ b - c = a - c (for some relation -) The one you're looking for is commutativity. Indeed; must have been echos of my previous life as a C++ programmer creeping into the Obj-C part of my brain (in C++, the std::set class uses less than, instead of equality, where transitivity is the important property, not commutativity). :) -- Clark S. Cox III clarkc...@gmail.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Nil items in NSMutableSet
On Mar 16, 2010, at 2:18 PM, Alejandro Rodriguez wrote: [ob isEqual:@hello]; //returns YES [@hello isEqual:ob]; //returns NO That may very well be the problem... now... I have no idea on how I will make the second test return YES. You can't do that in Objective-C, unfortunately. It would require splicing into NSString's implementation of -isEqual: and adding your own test before the existing one. (You could probably do it by messing with the runtime to replace the method, but that would be very nasty.) This basically allows me to do something like [messageSet member:@123] and return the object with ID 123 or [memberSet member:messageObject] and have the same result. It might be convenient to do that, but there isn't a clean way to implement it. You'll need to think of another way to do what you want to do. One possibility is to use an NSDictionary mapping identifiers to your objects. —Jens___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Nil items in NSMutableSet
On Tue, Mar 16, 2010 at 2:18 PM, Alejandro Rodriguez l.mephi...@gmail.com wrote: You were right, my equality is not transitive. id ob = [[objectClass alloc] initWithId:@hello]; [ob isEqual:@hello]; //returns YES [@hello isEqual:ob]; //returns NO That may very well be the problem... now... I have no idea on how I will make the second test return YES. I doubt that you can. You'll likely have to give up on the idea of being able to pass a string to -member:. You could implement the check in a method of your own in a category on NSSet. doesn't that depend on the implementation of isEqual of the asking object in this case NSString? Yes. Have any of you had to deal with this before? I'll dive into the docs and see what details I find that might be useful. Seems we are getting somewhere cheers! Alejandro On Mar 16, 2010, at 2:45 PM, Clark Cox wrote: On Tue, Mar 16, 2010 at 11:35 AM, Thomas Davie tom.da...@gmail.com wrote: Your code doesn't account for the possibility that the order of comparison might happen in the other order (i.e. [@123 isEqual: object]). I wouldn't be surprised if NSSet is assuming that equality is transitive (i.e. [a isEqual: b] == [b isEqual: a]). For reference, this property is not transitivity, the transitivity relation is: a - b ^ b - c = a - c (for some relation -) The one you're looking for is commutativity. Indeed; must have been echos of my previous life as a C++ programmer creeping into the Obj-C part of my brain (in C++, the std::set class uses less than, instead of equality, where transitivity is the important property, not commutativity). :) -- Clark S. Cox III clarkc...@gmail.com -- Clark S. Cox III clarkc...@gmail.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Nil items in NSMutableSet
Yeah I could experiment with Method Swizzling but that is just playing dirty. I will follow your advice and just move away from this implementation into something nicer like a dictionary. After all I can always do [dict valueForKey:[ob objectId]]; to get the same result as [set member:ob] Thank you very much for Clark, Thomas and Jens. Regards to all, Alejandro Rodríguez On Mar 16, 2010, at 5:42 PM, Clark Cox wrote: On Tue, Mar 16, 2010 at 2:18 PM, Alejandro Rodriguez l.mephi...@gmail.com wrote: You were right, my equality is not transitive. id ob = [[objectClass alloc] initWithId:@hello]; [ob isEqual:@hello]; //returns YES [@hello isEqual:ob]; //returns NO That may very well be the problem... now... I have no idea on how I will make the second test return YES. I doubt that you can. You'll likely have to give up on the idea of being able to pass a string to -member:. You could implement the check in a method of your own in a category on NSSet. doesn't that depend on the implementation of isEqual of the asking object in this case NSString? Yes. Have any of you had to deal with this before? I'll dive into the docs and see what details I find that might be useful. Seems we are getting somewhere cheers! Alejandro On Mar 16, 2010, at 2:45 PM, Clark Cox wrote: On Tue, Mar 16, 2010 at 11:35 AM, Thomas Davie tom.da...@gmail.com wrote: Your code doesn't account for the possibility that the order of comparison might happen in the other order (i.e. [@123 isEqual: object]). I wouldn't be surprised if NSSet is assuming that equality is transitive (i.e. [a isEqual: b] == [b isEqual: a]). For reference, this property is not transitivity, the transitivity relation is: a - b ^ b - c = a - c (for some relation -) The one you're looking for is commutativity. Indeed; must have been echos of my previous life as a C++ programmer creeping into the Obj-C part of my brain (in C++, the std::set class uses less than, instead of equality, where transitivity is the important property, not commutativity). :) -- Clark S. Cox III clarkc...@gmail.com -- Clark S. Cox III clarkc...@gmail.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Nil items in NSMutableSet
There was a thread on this list a few days ago about effective method swizzling into Apple classes. Despite being replete with warnings about Don't use it in production code, it IS doable, and very, very cool, IMHO. -Dan On Mar 16, 2010, at 2:18 PM, Alejandro Rodriguez wrote: You were right, my equality is not transitive. id ob = [[objectClass alloc] initWithId:@hello]; [ob isEqual:@hello]; //returns YES [@hello isEqual:ob]; //returns NO That may very well be the problem... now... I have no idea on how I will make the second test return YES. doesn't that depend on the implementation of isEqual of the asking object in this case NSString? Have any of you had to deal with this before? I'll dive into the docs and see what details I find that might be useful. Seems we are getting somewhere cheers! Alejandro On Mar 16, 2010, at 2:45 PM, Clark Cox wrote: On Tue, Mar 16, 2010 at 11:35 AM, Thomas Davie tom.da...@gmail.com wrote: Your code doesn't account for the possibility that the order of comparison might happen in the other order (i.e. [@123 isEqual: object]). I wouldn't be surprised if NSSet is assuming that equality is transitive (i.e. [a isEqual: b] == [b isEqual: a]). For reference, this property is not transitivity, the transitivity relation is: a - b ^ b - c = a - c (for some relation -) The one you're looking for is commutativity. Indeed; must have been echos of my previous life as a C++ programmer creeping into the Obj-C part of my brain (in C++, the std::set class uses less than, instead of equality, where transitivity is the important property, not commutativity). :) -- Clark S. Cox III clarkc...@gmail.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/danhd123%40mac.com This email sent to danhd...@mac.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Nil items in NSMutableSet
Doing this with a class cluster like NSString would be difficult and especially fragile, as you'd have to make sure to do the appropriate swizzling for every hidden subclass of NSString that might have its own implementation of -isEqual:; including those that may be introduced (or removed) in updates to the OS. On Tue, Mar 16, 2010 at 3:34 PM, Daniel DeCovnick danhd...@mac.com wrote: There was a thread on this list a few days ago about effective method swizzling into Apple classes. Despite being replete with warnings about Don't use it in production code, it IS doable, and very, very cool, IMHO. -Dan On Mar 16, 2010, at 2:18 PM, Alejandro Rodriguez wrote: You were right, my equality is not transitive. id ob = [[objectClass alloc] initWithId:@hello]; [ob isEqual:@hello]; //returns YES [@hello isEqual:ob]; //returns NO That may very well be the problem... now... I have no idea on how I will make the second test return YES. doesn't that depend on the implementation of isEqual of the asking object in this case NSString? Have any of you had to deal with this before? I'll dive into the docs and see what details I find that might be useful. Seems we are getting somewhere cheers! Alejandro On Mar 16, 2010, at 2:45 PM, Clark Cox wrote: On Tue, Mar 16, 2010 at 11:35 AM, Thomas Davie tom.da...@gmail.com wrote: Your code doesn't account for the possibility that the order of comparison might happen in the other order (i.e. [@123 isEqual: object]). I wouldn't be surprised if NSSet is assuming that equality is transitive (i.e. [a isEqual: b] == [b isEqual: a]). For reference, this property is not transitivity, the transitivity relation is: a - b ^ b - c = a - c (for some relation -) The one you're looking for is commutativity. Indeed; must have been echos of my previous life as a C++ programmer creeping into the Obj-C part of my brain (in C++, the std::set class uses less than, instead of equality, where transitivity is the important property, not commutativity). :) -- Clark S. Cox III clarkc...@gmail.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/danhd123%40mac.com This email sent to danhd...@mac.com -- Clark S. Cox III clarkc...@gmail.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Nil items in NSMutableSet
Daniel, Method swizzling is fine for debugging purposes, but should not be used in production code. This has already been said by some people who really, really know what they're talking about. And it's *very* dangerous to swizzle something on NSString. The first reason (of many) that comes to mind, is that most of Apple's own internal Objective-C frameworks are using NSStrings, in ways and situations you can't predict. So by advising someone to mess with NSString's implementation, you are advising them to potentially break their app in countless ways (possibly even data-corrupting ones) and then send that app to unsuspecting users. Not a great piece of advise, in my book. -Steven On Tue, Mar 16, 2010 at 6:34 PM, Daniel DeCovnick danhd...@mac.com wrote: There was a thread on this list a few days ago about effective method swizzling into Apple classes. Despite being replete with warnings about Don't use it in production code, it IS doable, and very, very cool, IMHO. -Dan On Mar 16, 2010, at 2:18 PM, Alejandro Rodriguez wrote: You were right, my equality is not transitive. id ob = [[objectClass alloc] initWithId:@hello]; [ob isEqual:@hello]; //returns YES [@hello isEqual:ob]; //returns NO That may very well be the problem... now... I have no idea on how I will make the second test return YES. doesn't that depend on the implementation of isEqual of the asking object in this case NSString? Have any of you had to deal with this before? I'll dive into the docs and see what details I find that might be useful. Seems we are getting somewhere cheers! Alejandro On Mar 16, 2010, at 2:45 PM, Clark Cox wrote: On Tue, Mar 16, 2010 at 11:35 AM, Thomas Davie tom.da...@gmail.com wrote: Your code doesn't account for the possibility that the order of comparison might happen in the other order (i.e. [@123 isEqual: object]). I wouldn't be surprised if NSSet is assuming that equality is transitive (i.e. [a isEqual: b] == [b isEqual: a]). For reference, this property is not transitivity, the transitivity relation is: a - b ^ b - c = a - c (for some relation -) The one you're looking for is commutativity. Indeed; must have been echos of my previous life as a C++ programmer creeping into the Obj-C part of my brain (in C++, the std::set class uses less than, instead of equality, where transitivity is the important property, not commutativity). :) -- Clark S. Cox III clarkc...@gmail.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/danhd123%40mac.com This email sent to danhd...@mac.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/steven.degutis%40gmail.com This email sent to steven.degu...@gmail.com -- Steven Degutis http://www.thoughtfultree.com/ http://www.degutis.org/ ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Nil items in NSMutableSet
I agree with the arguments against swizzling. While I'm not yet convinced that the isEqual: problem is what really is causing my crash I do feel that the way I'm using the NSSet and the objects is too hackish for the stability and quality I want to achive in my app (as the docs say: don't fight the framework) therefore I've decided to move away from that approach and use a more conventional method with NSDictionary although I must admit that I really loved using sets that way, it made a few things very fast and easy. Alejandro Sent from my iPhone On Mar 16, 2010, at 7:22 PM, Steven Degutis steven.degu...@gmail.com wrote: Daniel, Method swizzling is fine for debugging purposes, but should not be used in production code. This has already been said by some people who really, really know what they're talking about. And it's *very* dangerous to swizzle something on NSString. The first reason (of many) that comes to mind, is that most of Apple's own internal Objective-C frameworks are using NSStrings, in ways and situations you can't predict. So by advising someone to mess with NSString's implementation, you are advising them to potentially break their app in countless ways (possibly even data-corrupting ones) and then send that app to unsuspecting users. Not a great piece of advise, in my book. -Steven On Tue, Mar 16, 2010 at 6:34 PM, Daniel DeCovnick danhd...@mac.com wrote: There was a thread on this list a few days ago about effective method swizzling into Apple classes. Despite being replete with warnings about Don't use it in production code, it IS doable, and very, very cool, IMHO. -Dan On Mar 16, 2010, at 2:18 PM, Alejandro Rodriguez wrote: You were right, my equality is not transitive. id ob = [[objectClass alloc] initWithId:@hello]; [ob isEqual:@hello]; //returns YES [@hello isEqual:ob]; //returns NO That may very well be the problem... now... I have no idea on how I will make the second test return YES. doesn't that depend on the implementation of isEqual of the asking object in this case NSString? Have any of you had to deal with this before? I'll dive into the docs and see what details I find that might be useful. Seems we are getting somewhere cheers! Alejandro On Mar 16, 2010, at 2:45 PM, Clark Cox wrote: On Tue, Mar 16, 2010 at 11:35 AM, Thomas Davie tom.da...@gmail.com wrote: Your code doesn't account for the possibility that the order of comparison might happen in the other order (i.e. [@123 isEqual: object]). I wouldn't be surprised if NSSet is assuming that equality is transitive (i.e. [a isEqual: b] == [b isEqual: a]). For reference, this property is not transitivity, the transitivity relation is: a - b ^ b - c = a - c (for some relation -) The one you're looking for is commutativity. Indeed; must have been echos of my previous life as a C++ programmer creeping into the Obj-C part of my brain (in C++, the std::set class uses less than, instead of equality, where transitivity is the important property, not commutativity). :) -- Clark S. Cox III clarkc...@gmail.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/danhd123%40mac.com This email sent to danhd...@mac.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/steven.degutis%40gmail.com This email sent to steven.degu...@gmail.com -- Steven Degutis http://www.thoughtfultree.com/ http://www.degutis.org/ ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com