4

so i have this weird problem that's been bugging me for the last few hours.

I have a framework in which I created a protocol named ChatDelegate (code bellow)

public protocol ChatDelegate: class {
   func chat(_ chatCollectionView:  UICollectionView, didSelect message: Message)
}

and a ViewController (not in the framework), which conforms to the ChatDelegate, like so

extension ChatContainerViewController: ChatDelegate {
   func chat(_ chatCollectionView: UICollectionView, didSelect message: Message) {
      print("did select")
   }
}

but the compiler still complains that the ChatContainerViewController does not conform to the protocol and I don't understand why?? The function has the exact same header (I also tried putting public in front ...didn't help).

Any help would be much appreciated.

UPDATE I figured it out. The problem was that I had Message class in my project and in the framework and the compiler didn't know which one to choose. Adding ModuleName in front (ModuleName.Message) fixed it. :D

Klemen Košir
  • 77
  • 1
  • 7
  • did you delegate with your chatCollectionView instance? – theduman Jan 24 '17 at 12:25
  • you mean this? let chatVC = ChatViewController.viewController(); chatVC.delegate = self; chatContainerView.addSubviewFromViewController(chatVC, useAutoLayout: true) – Klemen Košir Jan 24 '17 at 13:18
  • Im having a similar problem. My protocol is written is swift and isnt added automatically to my framework.h header file, so i added the .swift file to public headers, but it still isnt being found. (the error I get is "No type named "protocolname" in module "frameworkName".) Any help with this would be greatly appreciated. – Jeremie D Sep 01 '17 at 14:07

1 Answers1

0

I had the same issue. The file that defined the protocol had a target membership in both the framework and the application targets. I solved the issue by making the file that defined the protocol only have a target membership in the framework and then adding an import <FrameworkName> to the code in the application target that needed to use the protocol.

Andrew
  • 7,630
  • 3
  • 42
  • 51