I need to convert my Objective-C to Swift to get an image of a contact from the Address Book. But I get an error with for cast from CFData
to NSData
and I don't know how make this work. What can I do to make this work correctly?
In Objective-C:
ABRecordID contactID = ABRecordGetRecordID(contactRef);
ABAddressBookRef addressBook = ABAddressBookCreate();
ABRecordRef origContactRef = ABAddressBookGetPersonWithRecordID(addressBook, contactID);
if (ABPersonHasImageData(origContactRef)) {
NSData *imgData = (NSData*)ABPersonCopyImageDataWithFormat(origContactRef, kABPersonImageFormatOriginalSize);
img = [UIImage imageWithData: imgData];
[imgData release];
}
CFRelease(addressBook);
return img;
In Swift:
var image: UIImage!
if ABPersonHasImageData(person) {
var imgData = (ABPersonCopyImageDataWithFormat(person, kABPersonImageFormatOriginalSize))
image = UIImage.imageWithData(imgData) //Here get the error
}