Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Obj-C头文件无法从Swift类识别协议_Ios_Objective C_Swift_Delegates_Protocols - Fatal编程技术网

Ios Obj-C头文件无法从Swift类识别协议

Ios Obj-C头文件无法从Swift类识别协议,ios,objective-c,swift,delegates,protocols,Ios,Objective C,Swift,Delegates,Protocols,我在Swift文件中定义了一个协议,Obj-C头文件无法识别该协议 MainViewController.h #import "AppDelegate.h" @interface MainViewController : UIViewController <UICollectionViewDataSource, UICollectionViewDelegate, AnotherViewControllerDelegate> @end #import "MyProject-Swif

我在Swift文件中定义了一个协议,Obj-C头文件无法识别该协议

MainViewController.h

#import "AppDelegate.h"

@interface MainViewController : UIViewController <UICollectionViewDataSource, UICollectionViewDelegate, AnotherViewControllerDelegate>
@end
#import "MyProject-Swift-Headers.h"
AppDelegate.h

#import "AppDelegate.h"

@interface MainViewController : UIViewController <UICollectionViewDataSource, UICollectionViewDelegate, AnotherViewControllerDelegate>
@end
#import "MyProject-Swift-Headers.h"
另一个视图控制器。swift

@objc protocol AnotherViewControllerDelegate {
    func closeView()
}

@objc class AnotherViewController: UIViewController{

     var delegate: AnotherViewControllerDelegate!

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

奇怪的是,在MainViewController.h中,当我开始键入“AnotherViewControllerDelegate”时,Xcode将自动完成。此外,“构建设置->打包”下的“定义模块”始终设置为“是”;我已经混合了Swift和Obj-C方法用于本项目代码库的其他部分。。。似乎无法使此协议正常工作。

它是
Switft.h
而不是
Swift头文件。h
也尝试导入
.m
文件。您能解释一下您声明的第一部分吗?此外,我还尝试在MainViewController的.m和.h文件中导入“MyProject Swift Headers.h”。。。获取了相同的错误。它是
MyProject Swift.h
而不是
MyProject Swift Headers.h
。检查这个苹果文档并阅读
将Swift导入Objective-C
我认为这不是问题所在,因为我一直在将“#import”MyProject Swift Headers.h”头文件导入其他Obj-C文件,并成功地使用了其他Swift方法。另外,我刚刚尝试复制了“MyProject Swift Headers.h”的内容“导入一个新创建的”MyProject Swift.h“文件,错误并没有消失。“找不到协议声明…”消息是错误还是警告?我见过这样的警告,结果证明对功能没有影响。您是否使用桥接标头?“生成设置”下“Objective-C生成的接口头名称”属性的值是多少?