Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing a contact detail in iOS using swift

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
like image 209
Govind Avatar asked Dec 06 '22 01:12

Govind


1 Answers

This works in Xcode 6 GM

let firstName = ABRecordCopyValue(contactRecord, kABPersonFirstNameProperty).takeRetainedValue() as String

Slightly more concise than the above example.

like image 192
jordan_maguire Avatar answered Dec 23 '22 21:12

jordan_maguire