I've been working on this problem for a while and can't seem to find the solution. In my app, I uniquely identify contacts from ABAddressBook
by their creation date, as no two contacts can be created at the same time. In my app, the creation date is stored in a string called uid
, as you can see below. I am checking to see if two contacts are the same, and I do this by performing the following conditional statement:
NSString *uid = @"some string";
if([(__bridge_transfer NSString *)ABRecordCopyValue(currentPersonRef, kABPersonCreationDateProperty) isEqualToString:uid]) {
//Do some code
}
However, when I run this code, I get the following error:
[__NSDate isEqualToString:]: unrecognized selector sent to instance 0x8c7c770
I'm pretty sure the problem is that ABRecordCopyValue()
is returning an NSDate object that is not being casted to NSString
by (__bridge_transfer NSString *)
, so when I compare it to uid
using isEqualToString
, it crashes. The thing is, I thought that by casting it to an NSString object, isEqualToString:
would work. My question is:
Why is the (__bridge_transfer NSString *) not casting the NSDate object?
EDIT:
The answers provided have been useful, but they do not completely address my problem (well actually they do, but I have a follow-up question). In another part of my code, I run this:
NSString *uid = (__bridge_transfer NSString *)ABRecordCopyValue(currentPerson, kABPersonCreationDateProperty);
And if I NSLog uid
I get this:
2012-10-28 21:55:29 +0000
So how would I compare uid
in the above conditional statement if isEqualToString:
doesn't work?