While using Objective-C we generally use the following code to get the details
NSString *firstName = (__bridge_transfer NSString *)ABRecordCopyValue(contactPerson, kABPersonFirstNameProperty);
In Swift I tried the following
var firstName : NSString = ABRecordCopyValue(contactPerson, kABPersonFirstNameProperty).takeUnretainedValue() as NSString
and I am not able to build because of the error
Bitcast requires both operands to be pointer or neither %224 = bitcast %objc_object* %223 to %PSs9AnyObject_, !dbg !486 Bitcast requires both operands to be pointer or neither %225 = bitcast %PSs9AnyObject_ %224 to i8*, !dbg !486 LLVM ERROR: Broken function found, compilation aborted! Command /Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift failed with exit code 1
This works in Xcode 6 GM
let firstName = ABRecordCopyValue(contactRecord, kABPersonFirstNameProperty).takeRetainedValue() as String
Slightly more concise than the above example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With