Re: Comparing NSDictionary woes
Re: Comparing NSDictionary woes
- Subject: Re: Comparing NSDictionary woes
- From: Diederik Hoogenboom <email@hidden>
- Date: Mon, 23 Jul 2007 07:45:40 +0200
Ken,
Are you using the same character encoding for strings in both
dictionaries? I see you are using UTF-8 for the PHP one.
Diederik
--
Diederik Hoogenboom
Obvious Matter - DiskLibrary for Mac
http://www.obviousmatter.com
On 23-jul-2007, at 2:33, Ken Tozier wrote:
On Jul 22, 2007, at 8:06 PM, Milo Bird wrote:
Dear Ken,
No, -isEqual: and -description are separate methods, with separate
logic. Objects with identical descriptions may be equal, but
depending on the implementation of those two methods they may well
not be.
For example, say you have an object representing a file on disk.
You will probably want to judge equality by comparing the paths of
the two files. However, when implementing the -description method
you may decide to print just the filename. In that case, two
objects representing different files with the same filename would
have the same description but would not be equal.
You might as well expect that all Johns in the world are actually
the same person, because their name is written the same.
AFAIK there is no problem with NSDicitionary's -isEqual:/-
isEqualToDictionary:, so this must be to do with the objects you
are putting into it. Please post some code.
One dictionary lives in a custom class the other is fetched
periodically from a PHP script on a server. The php derived
dictionary is coerced from the return value of an NSURLConnection
like so
result = [NSURLConnection sendSynchronousRequest: request
returningResponse: &response
error: &error];
// process result if any
if ((result != nil) && ([result length] > 0))
{
NSString *temp = [[[NSString alloc] initWithBytes: [result bytes]
length: [result length]
encoding: NSUTF8StringEncoding]
stringByTrimmingCharactersInSet: returnChars];
return [temp propertyList];
}
else if (error != NULL)
{
// something went awry log HTTP header and error
NSLog(@"response = %@", [response allHeaderFields]);
NSLog(@"error = %@", error);
}
The compare is done like this
if ([selfRecord isEqualToDictionary: phpRecord] == NO)
/* update object */
The only thing I can think of is that NSString's propertyList
method isn't unpacking "<real>2.5</real>" in a way that would yeild
isEqual = YES for a real stored in an NSNumber like this [NSNumber
numberWithDouble: 2.5]. Both dictionaries contain a lot of reals
maybe that's the problem. All other values are ints and strings.
I found one link here: http://lists.apple.com/archives/Cocoa-dev/
2004/Mar/msg01734.html which had a similar problem only with date
values dropping sub-second values during serialization/
deserialization.
For now, I have a workaround where rather than fetching the dict
from the PHP script and comparing them on the Cocoa end, I send the
dict to a PHP script and compare them on the PHP end. The PHP
compare flags them as the same if their values are identical so
that's good enough for now.
Ken
_______________________________________________
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:
40obviousmatter.com
This email sent to email@hidden
_______________________________________________
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