开发者

How do I compare two CFUUIDs (Mac OS X Carbon/CoreFoundation)?

How can I compare two CFUUIDRefs from the CoreFoundation Carbon framework in Mac OS X? Is there an easier way to check if two CFUUIDs are equal other than converting them to string开发者_C百科s and then comparing those?


A CFUUID is a kind of CFType, so you would use the same CFEqual function you use for any other CF objects.


I'm not sure if there is a canonical or recommended method per se, but would the following suffice?

#define CompareUUIDs(u1, u2) memcmp(CFUUIDGetUUIDBytes(u1), CFUUIDGetUUIDBytes(u2))

It would be used as follows:

if (CompareUUIDs(u1, u2) == 0) {
    // UUIDs are equal
} // etc..

Alternatively, as you're only really interested in whether they are equal or not:

#define UUIDsAreEqual(u1, u2) (memcmp(CFUUIDGetUUIDBytes(u1), CFUUIDGetUUIDBytes(u2)) == 0)

It would be used as follows:

if (UUIDsAreEqual(u1, u2)) {
    // UUIDs are equal
} // etc..
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜