0

In a Project having already ObjC, I'm adding a Swift Class

import AddressBookUI
class MyVC : UITableViewController, ABPeoplePickerNavigationControllerDelegate {
}

MyApp-Swift.h:289:42: Cannot find protocol declaration for 'ABPeoplePickerNavigationControllerDelegate'; did you mean 'UINavigationControllerDelegate'?

No, Swift, I really mean ABPeoplePickerNavigationControllerDelegate. Really wondering what I am doing wrong here...

StuFF mc
  • 4,137
  • 2
  • 33
  • 32
  • check this https://developer.apple.com/library/ios/documentation/AddressBookUI/Reference/ABPeoplePickerNavigationControllerDelegate_Protocol/ – Ajumal Mar 25 '15 at 10:42
  • You think I didn't? I've worked with the AB Framework since 2008..... Something is just a bit different in Swift — and it probably have nothing to do with AB but generally me not understand something with Swift/ObjC. – StuFF mc Mar 25 '15 at 11:07
  • just import a swift file name it MyVC and just use your above code and don't put your above code in header file. – Dheeraj Singh Mar 25 '15 at 11:15

4 Answers4

1

I need to add

#import <AddressBookUI/AddressBookUI.h>

in my Briding-Header.h. One could think the import in my Swift file was enough. It was not.

That said, now I have a new problem when implementing

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

Here comes the next error:

-Swift.h:297:110: Expected a type

It has a problem with the ABRecord type in

didSelectPerson:(ABRecord)

Doesn't help if I also import AddressBook in Briding Header or Swift File.

StuFF mc
  • 4,137
  • 2
  • 33
  • 32
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
Diego Freniche
  • 5,225
  • 3
  • 32
  • 45
1

FWIW, the reason this works with ABRecord in pure Swift, but not in the Objective-C compatibility header is that there is a typealias which the latter apparently doesn't translate back correctly:

typealias ABRecordRef = ABRecord

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

Might be worth filing a Radar

NeoNacho
  • 680
  • 1
  • 5
  • 13
0

Fixed my second Problem thanks to @neonacho on Twitter. Instead of ABRecord I had to use ABRecordRef to compile. Not sure why Diego's code works and not mine. So it became

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

and it works.

StuFF mc
  • 4,137
  • 2
  • 33
  • 32