0

在已经拥有 ObjC 的项目中,我正在添加一个 Swift 类

import AddressBookUI
class MyVC : UITableViewController, ABPeoplePickerNavigationControllerDelegate {
}

MyApp-Swift.h:289:42:找不到“ABPeoplePickerNavigationControllerDelegate”的协议声明;你的意思是“UINavigationControllerDelegate”吗?

不,斯威夫特,我真的是说ABPeoplePickerNavigationControllerDelegate。真的想知道我在这里做错了什么......

4

4 回答 4

1

You can check the code I've used here

Pure Swift project, no Objective-C involved

For me, this is compiling fine without using any Bridging-Header

import UIKit
import AddressBook
import AddressBookUI

class ViewController: UITableViewController, ABPeoplePickerNavigationControllerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    func peoplePickerNavigationController(peoplePicker: ABPeoplePickerNavigationController!, didSelectPerson person: ABRecord!, property: ABPropertyID, identifier: ABMultiValueIdentifier) {


    }
}

I'm adding relevant frameworks (AddressBook, AddressBookUI) to the link binary with libraries phase of my target

adding relevant frameworks

Objective-C Project, with Bridging Header

My Bridging-Header.h:

#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h>
  • make sure your Bridging-Header is properly referenced in your target

Bridging-Header

  • swift VC code is the same as above
于 2015-03-25T11:14:28.190 回答
1

我需要添加

#import <AddressBookUI/AddressBookUI.h>

在我的Briding-Header.h. 可以认为import我的 Swift 文件中的 足够了。不是。

也就是说,现在我在实施时遇到了一个新问题

func peoplePickerNavigationController(peoplePicker: ABPeoplePickerNavigationController!, didSelectPerson person: ABRecord!, property: ABPropertyID, identifier: ABMultiValueIdentifier) {
}

这是下一个错误:

-Swift.h:297:110:需要一个类型

ABRecord输入的类型有问题

didSelectPerson:(ABRecord)

如果我还导入AddressBookBriding Header 或 Swift File 也无济于事。

于 2015-03-25T11:01:09.013 回答
1

FWIW,这ABRecord在纯 Swift 中有效,但在 Objective-C 兼容性标头中无效的原因是typealias,后者显然不能正确转换回来:

typealias ABRecordRef = ABRecord

请参阅https://developer.apple.com/library/prerelease/ios/documentation/AddressBook/Reference/ABRecordRef_iPhoneOS/index.html#//apple_ref/c/tdef/ABRecordRef

可能值得提交雷达

于 2015-03-25T13:03:15.893 回答
0

感谢Twitter 上的@neonacho,解决了我的第二个问题。而不是我不得不使用来编译。不知道为什么 Diego 的代码有效而不是我的。于是就变成了ABRecordABRecordRef

func peoplePickerNavigationController(peoplePicker: ABPeoplePickerNavigationController!, 
                                      didSelectPerson person: ABRecordRef!, property: ABPropertyID, identifier: ABMultiValueIdentifier) {
}

它有效。

于 2015-03-25T12:56:09.823 回答