Re: An apparent equality is not...
Re: An apparent equality is not...
- Subject: Re: An apparent equality is not...
- From: Wain <email@hidden>
- Date: Wed, 2 Aug 2006 22:31:57 +0100
Hi,
I think you probably meant to perform a different type of comparison:
[currentLabel isEqualToString:label].
Two NSStrings can contain the same list of characters and will
therefore print the same list of characters but they can still be
different depending on what you compare (the pointer to the NSString
objects).
i.e. you want to compare the contents of the NSStrings and not the
location at which they are stored...
have a look at: http://www.macdevcenter.com/pub/a/mac/2001/06/29/
cocoa.html?page=3 for more info
Wain
On 2 Aug 2006, at 22:02, Brad Bumgarner wrote:
Below are two methods that I am currently working on. The first
method, (personalInformationFor:) calls the second method
(valueForProperty:givenLabel:). The purpose of these methods is to
extract information from a supplied ABRecord. The
valueForProperty:givenLabel: method SHOULD return the value for the
ABMultiValue that matches the supplied label or an empty string if
there is no match.
The problem that I am encountering is that even though the suppled
label (label) appears to be matching (currentLabel) the match is
never registered (i.e.: "return [multiValue valueAtIndex: x]" never
gets called.) In the debugger, the summaries appear to be
identical. Doing a "print-object" in the console shows the contents
are the same and both are of the same class. What I have noticed,
however, is that the value column in the debugger shows two
different values. How is that possble? And, what do I need to
change to make this work?
+(NSDictionary *)personalInformationFor: (ABRecord *)record {
int x, count;
ABMultiValue *multiValue;
NSMutableDictionary *personalInfo;
NSArray *multiValueProperties, *multiValueLabels, *keys;
multiValueProperties = [NSArray arrayWithObjects:
kABPhoneProperty, kABPhoneProperty,
kABEmailProperty, nil];
multiValueLabels = [NSArray arrayWithObjects: kABPhoneWorkLabel,
kABPhoneWorkFAXLabel,
kABEmailWorkLabel, nil];
keys = [NSArray arrayWithObjects: @"workPhone", @"workFax",
@"workEmail", nil];
personalInfo = [NSMutableDictionary dictionary];
[personalInfo setObject: [record valueForProperty:
kABFirstNameProperty] forKey: @"firstName"];
[personalInfo setObject: [record valueForProperty:
kABLastNameProperty] forKey: @"lastName"];
[personalInfo setObject: [record valueForProperty:
kABOrganizationProperty] forKey: @"company"];
count = [multiValueProperties count];
for (x = 0; x < count; x++) {
multiValue = [record valueForProperty: [multiValueProperties
objectAtIndex: x]];
[personalInfo setObject: [self valueForProperty: multiValue
givenLabel: [multiValueLabels objectAtIndex: x]]
forKey: [keys objectAtIndex: x]];
}
return personalInfo;
}
+(NSString *)valueForProperty: (ABMultiValue *)multiValue
givenLabel: (NSString *)label {
int x, count;
NSString *currentLabel;
count = [multiValue count];
for (x = 0; x < count; x++) {
currentLabel = [multiValue labelAtIndex: x];
if (currentLabel == label)
return [multiValue valueAtIndex: x];
}
return @"";
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden