Re: isEqual, isEqualToString, compare behaviors
Re: isEqual, isEqualToString, compare behaviors
- Subject: Re: isEqual, isEqualToString, compare behaviors
- From: Yvan BARTHÉLEMY <email@hidden>
- Date: Fri, 27 Mar 2009 20:07:57 +0100
isEqualXXX methods returns a boolean and not a NSComaprisonResult like
compare:. So, for these 0 == NO, and 1 == YES. No problem then.
Le 27 mars 09 à 19:30, Ameen a écrit :
am not being able to explain the output of the following code; code
and output pasted below.
#import <Cocoa/Cocoa.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSComparisonResult compareResult = 0;
id fileAttributes = nil;
if(fileAttributes = [[NSFileManager defaultManager]
fileAttributesAtPath:@"/Applications"
traverseLink:FALSE]) {
NSLog(@"[fileAttributes objectForKey:NSFileType] = %@;
NSDirectoryFileType = %@",[fileAttributes
objectForKey:NSFileType],NSDirectoryFileType);
compareResult = [(NSString *) [fileAttributes
objectForKey:NSFileType] isEqualToString:NSDirectoryFileType];
NSLog(@"[(NSString *) [fileAttributes objectForKey:NSFileType]
isEqualToString:NSDirectoryFileType] = %d",compareResult);
compareResult = [(NSString *) [fileAttributes
objectForKey:NSFileType] compare:NSDirectoryFileType];
NSLog(@"[(NSString *) [fileAttributes objectForKey:NSFileType]
compare:NSDirectoryFileType] = %d",compareResult);
compareResult = [[fileAttributes
objectForKey:NSFileType] isEqual:NSDirectoryFileType];
NSLog(@"[[fileAttributes objectForKey:NSFileType]
isEqual:NSDirectoryFileType] = %d",compareResult);
compareResult = [[fileAttributes
objectForKey:NSFileType] isEqual:[fileAttributes
objectForKey:NSFileType]];
NSLog(@"[[fileAttributes objectForKey:NSFileType] isEqual:
[fileAttributes objectForKey:NSFileType]] = %d",compareResult);
compareResult = [NSDirectoryFileType
isEqual:NSDirectoryFileType];
NSLog(@"[NSDirectoryFileType isEqual:NSDirectoryFileType] =
%d",compareResult);
}
[pool drain];
return 0;
}
/****************** output (target system OS X 10.5.6, using XCode
3.0)*********************/
[fileAttributes objectForKey:NSFileType] = NSFileTypeDirectory;
NSDirectoryFileType = NXDirectoryFileType
[(NSString *) [fileAttributes objectForKey:NSFileType]
isEqualToString:NSDirectoryFileType] = 0 //This shouldn't have been
true. because both strings are different.
[(NSString *) [fileAttributes objectForKey:NSFileType]
compare:NSDirectoryFileType] = -1 //OK they are not same. fine.
[[fileAttributes objectForKey:NSFileType]
isEqual:NSDirectoryFileType] = 0 //How come ?
[[fileAttributes objectForKey:NSFileType] isEqual:[fileAttributes
objectForKey:NSFileType]] = 1 //This cannot be true. An object
should be equal to itself.
[NSDirectoryFileType isEqual:NSDirectoryFileType] = 1 //This cannot
be true. An object should be equal to itself.
any body knows why this behavior.
_______________________________________________
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
_______________________________________________
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