简体   繁体   English

Xcode 13 桥接 Header 似乎找到了我的 Obj-C 类

[英]Xcode 13 Bridging Header does seem to find my Obj-C classes

I know this question might have been posted multiple times, but I haven't find any solution for 2 days despite looking closely all the answers in here.我知道这个问题可能已多次发布,但尽管仔细查看了此处的所有答案,但我已经 2 天没有找到任何解决方案。

I have an Objective-C data model I want to use in my Swift application.我有一个 Objective-C 数据 model 我想在我的 Swift 应用程序中使用。

So when adding my DataModel.m in my Models folder, it created MyApp-Bridging-Header.h inside the Models folder as well.因此,当在我的Models文件夹中添加我的DataModel.m时,它也在Models文件夹中创建了MyApp-Bridging-Header.h

在此处输入图像描述

I try several things in the Bridging-Header file to import my ProjectModel.h like:我在 Bridging-Header 文件中尝试了几件事来导入我的ProjectModel.h ,例如:

#import "ProjectModel.h" #import "ProjectModel.h"

#import "Models/ProjectModel.h" #import "模型/ProjectModel.h"

#import "MyApp/Models/ProjectModel.h" #import "MyApp/Models/ProjectModel.h"

But none seems to works as I would like.但似乎没有一个像我想要的那样工作。

The Bridging-Header file is defined as well in the Build Settings (see below) Bridging-Header 文件也在构建设置中定义(见下文)

在此处输入图像描述

在此处输入图像描述

But as soon as I try to compile the project I keep having the error: Cannot find type 'ProjectModel' in scope (like below)但是,一旦我尝试编译项目,我就会一直出现错误:在 scope 中找不到类型“ProjectModel” (如下所示)

在此处输入图像描述

And when using auto-completion on ProjectModel I got this warning:在 ProjectModel 上使用自动完成时,我收到了以下警告:

在此处输入图像描述

I don't know what I am missing right now, I would appreciate any help, plus, I'd rather specify, I am doing this on macOS Monterey with Xcode 13.1 .我不知道我现在缺少什么,我将不胜感激,另外,我宁愿指定,我正在使用Xcode 13.1macOS Monterey上执行此操作。

Add the following line at the beginning of the Swift file that uses the model:在使用 model 的Swift文件的开头添加以下行:

import ProjectModel

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM