-1

I was attempting to use this swift pod in my objective-c project. I got the compiler to recognize the class by using #import "PIDatePicker-swift.h" in my objective-c MyClass.m file, and was able to create a PIDatePicker object, but the method Apple recommends for conforming to the swift protocol, in this case PIDatePickerDelegate, gave me the error: "No type of protocol named PIDatePickerDelegate."

ManInTheArena
  • 89
  • 1
  • 9
  • 2
    My god... not only is your question totally unclear, but as your self-answer indicates, **you KNOW it's a duplciate** of [Using a Swift protocol in Objective-C](http://stackoverflow.com/q/26471898/2792531)... – nhgrif Apr 20 '16 at 22:26
  • This is a common problem users of Cocoa pods will encounter when mixing Swift and Objective C code. It's not exactly a duplicate because I am using a Pod and the answer linked does not. So, I reasoned that a new question was warranted; this is why I added, "However, if you're working with a swift podfile, as I was, it's not always clear what to do, and so I am posting this for any others who may be in the same fix" to my answer. – ManInTheArena May 10 '16 at 23:38

1 Answers1

-1

The fix for this was adding the following @objc tag to the swift file protocol definition, in this case, PIDatePickerDelegate.swift:

    public protocol PIDatePickerDelegate {
    func pickerView(pickerView: PIDatePicker, didSelectRow row: Int, inComponent component: Int)
}   

Just changed the above to:

@objc public protocol PIDatePickerDelegate {
    func pickerView(pickerView: PIDatePicker, didSelectRow row: Int, inComponent component: Int)
} 

This is also answered here:

Using a Swift protocol in Objective-C

However, if you're working with a swift podfile, as I was, it's not always clear what to do, and so I am posting this for any others who may be in the same fix. The troubleshooting section of Apple's Using Swift with Objective-C docs also has this line:

  • To be accessible and usable in Objective-C, a Swift class must be a descendant of an Objective-C class or it must be marked @objc.
Community
  • 1
  • 1
ManInTheArena
  • 89
  • 1
  • 9