views:

77

answers:

1

I am just curious if there is a way to swap the two stings in this example?

// This works
for(eachArtist in artistCollection) {
if([objFirName isEqualToString: [eachArtist firName]]) NSLog(@"DELETE ....");
}

What I was trying to do was (see below) can this be done or is the above the only way?

[eachArtist firName isEqualToString: objFirName]

eachArtist.firName is a NSString within an array of objects, objFirName is a vanilla NSString.

gary

A: 

If you have synthesized the firName property in the Artist implementation, the two approaches are equivalent.

That is:

[eachArtist firName]

is the same as

eachArtist.firName

If the @property is @synthesize-d in Artist.m and readwrite or readonly in Artist.h.

Since you are performing an isEqualToString predicate and not a less-than or greater-than predicate, it doesn't matter the order in which elements are in the predicate.

In mathematical terms, A = B if and only if B = A, for the purposes of comparing strings.

Alex Reynolds
Chuck Thats exactly what I wanted. @Alex Reynolds, many thanks, the only reason for wanting to swap the positions was to make the code read better.
fuzzygoat