Swift Compile Error Bitcast requires both operands to be pointer or neither

假如想象 提交于 2019-12-25 03:54:42

问题


In Xcode6 beta 1 something similar to this worked, however with Xcode6 beta 4 there were errors. After fixing the errors the errorless code I have is below

For Background: The class I'm using here implements ABPeoplePickerNavigationControllerDelegate which allows you the user to select a contact from the address book. I want to get the first email that is added to that person.

func peoplePickerNavigationController(peoplePicker: ABPeoplePickerNavigationController!,didSelectPerson person: ABRecordRef!) {

    var emails = ABRecordCopyValue(person, kABPersonEmailProperty)
    var emailsObj = emails.takeUnretainedValue() as AnyObject
    var index = 0 as CFIndex
    var emailAddress = ABMultiValueCopyValueAtIndex(emailsObj, index)

    println(emailAddress)
}

However when I compile I get Build Failed:

Bitcast requires both operands to be pointer or neither %80 = bitcast %objc_object* %79 to %PSs9AnyObject_, !dbg !860 Stored value type does not match pointer operand type! store %PSs9AnyObject_ %80, %objc_object** %81, align 4, !dbg !860 %objc_object*Stored value type does not match pointer operand type! store %PSs9AnyObject_ %80, %objc_object** %85, align 4, !dbg !864 %objc_object*LLVM ERROR: Broken function found, compilation aborted! Command /Applications/Xcode6-Beta4.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift failed with exit code 1

The suspect lines are:

var emailsObj = emails.takeUnretainedValue() as AnyObject
var emailAddress = ABMultiValueCopyValueAtIndex(emailsObj, index)

When I change the code to

func peoplePickerNavigationController(peoplePicker: ABPeoplePickerNavigationController!,didSelectPerson person: ABRecordRef!) {

    var emails = ABRecordCopyValue(person, kABPersonEmailProperty)
    var emailsObj:AnyObject? = emails.takeRetainedValue() as AnyObject
    var index = 0 as CFIndex
    var emailAddress = ABMultiValueCopyValueAtIndex(emailsObj, index)

    println(emailAddress)
}

The error shortens to

Bitcast requires both operands to be pointer or neither %79 = bitcast %objc_object* %78 to %PSs9AnyObject_, !dbg !856 Stored value type does not match pointer operand type! store %PSs9AnyObject_ %79, %objc_object** %80, align 8, !dbg !856 %objc_object*LLVM ERROR: Broken function found, compilation aborted! Command /Applications/Xcode6-Beta4.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift failed with exit code 1

Thanks in advance for any help

Aaron


回答1:


func peoplePickerNavigationController(peoplePicker: ABPeoplePickerNavigationController!,didSelectPerson person: ABRecordRef!) {

    var unmanagedEmails = ABRecordCopyValue(person, kABPersonEmailProperty)
    let emailObj: ABMultiValueRef = Unmanaged.fromOpaque(unmanagedEmails.toOpaque()).takeUnretainedValue() as NSObject as ABMultiValueRef

    var index = 0 as CFIndex

    var unmanagedEmail = ABMultiValueCopyValueAtIndex(emailObj, index)
    var emailAddress:String = Unmanaged.fromOpaque(unmanagedEmail.toOpaque()).takeUnretainedValue() as NSObject as String

    println(emailAddress)

}

More full answer can be found here.



来源:https://stackoverflow.com/questions/25089448/swift-compile-error-bitcast-requires-both-operands-to-be-pointer-or-neither

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!