Obj-C header file not recognizing protocol from Swift class

谁说胖子不能爱 提交于 2019-12-13 14:14:18

问题


I've defined a protocol in a Swift file that isn't being recognized by an Obj-C header file.

MainViewController.h

#import "AppDelegate.h"

@interface MainViewController : UIViewController <UICollectionViewDataSource, UICollectionViewDelegate, AnotherViewControllerDelegate>
@end

In th file above, I'm getting the following error:

Cannot find protocol declaration for "AnotherViewControllerDelegate"; did you mean "UIPageViewControllerDelegate"?

MainViewController.m

#import "MainViewController.h"
#import "AppDelegate.h"

@implementation MainViewController

-void closeView{
     NSLog(@"Why doesn't this work?");
}

@end

AppDelegate.h

#import "MyProject-Swift-Headers.h"

AnotherViewController.swift

@objc protocol AnotherViewControllerDelegate {
    func closeView()
}

@objc class AnotherViewController: UIViewController{

     var delegate: AnotherViewControllerDelegate!

     @IBAction func closeButton(sender: UIButton) {
          delegate.closeView()
     }
}

What's strange is that in MainViewController.h, Xcode will autocomplete when I start typing "AnotherViewControllerDelegate". Additionally, "Defines Modules" under Build Settings -> Packaging has always been set to "Yes"; I've mixed Swift and Obj-C methods for other parts of this project's codebase... just can't seem to get this protocol to work.

来源:https://stackoverflow.com/questions/39382652/obj-c-header-file-not-recognizing-protocol-from-swift-class

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