< Previous PageNext Page > Hide TOC

Comparing Objects

You compare two Core Foundation objects with the CFEqual function. If the two objects are essentially equal, the function returns a boolean true value. “Essential” equality depends on the type of objects compared. For example, when you compare two CFString objects, Core Foundation considers them essentially equal when they match character by character, regardless of their encodings or mutability attribute. Two CFArray objects are considered equal when they have the same count of elements and each element object in one array is essentially equal with its counterpart in the other array. Obviously, compared objects must be of the same type (or a mutable or immutable variant of the same type) to be considered equal.

The following code fragment shows how you might use the CFEqual function to compare a constant with a passed-in parameter:

Listing 1  Comparing Core Foundation objects

void stringTest(CFStringRef myString) {
    Boolean equal = CFEqual(myString, CFSTR("Kalamazoo"));
    if (!equal) {
        printf("They’re not equal!");
    }
    else {
        printf("They’re equal!"):
    }
}


< Previous PageNext Page > Hide TOC


© 2003, 2005 Apple Computer, Inc. All Rights Reserved. (Last updated: 2005-08-11)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.