On Oct 7, 2009, at 6:12 AM, Jim Correia wrote:

The documentation for -[NSAttributedString isEqualToAttributedString:] says:

Attributed strings must match in both characters and attributes to be equal.

It doesn't mention attachments at all.

Consider the following code:

attributedString is the input string, and it may contain image attachments

NSData *d = [NSKeyedArchiver archivedDataWithRootObject: attributedString]; NSAttributedString *s1 = [NSKeyedUnarchiver unarchiveObjectWithData: d]; NSAttributedString *s2 = [NSKeyedUnarchiver unarchiveObjectWithData: d];

        NSLog(@"isEqual = %d", [s1 isEqualToAttributedString: s2]);

When 'attriburedString' does not contain image attachments, 1 is logged.

When 'attributedString' does contains image attachments, 0 is logged.

Is this the expected behavior? The correct behavior?

Attributed string comparison for equality is somewhat problematic, because there are so many different types of attribute values. Some are simple value objects, with a straightforward equality comparison, but some--notably attachments, blocks, and lists--are not, and don't really have a notion of equality distinct from identity. If you need to compare two attributed strings, you may need to consider exactly what notion of equivalence you're looking for, and implement something to test for that.

Douglas Davidson

_______________________________________________

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

Reply via email to