ios Xcode 不会自动创建桥接头?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31716413/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 07:02:58  来源:igfitidea点击:

Xcode not automatically creating bridging header?

iosobjective-cswiftxcodebridging-header

提问by John Durand

I imported an Obj-C file into my swift project and Xcode automatically prompted me to create a bridging header file as expected. However, I deleted both the files (moved to trash) to make some changes, but when i try to import the Obj-C file once again, the prompt doesn't come up anymore. What is the reason? I even tested this same scenario in another project, It seems once I delete Xcode's auto created bridging header, It won't bring the prompt up again another time. Why is this?

我将一个 Obj-C 文件导入到我的 swift 项目中,Xcode 自动提示我按预期创建桥接头文件。但是,我删除了这两个文件(移至垃圾箱)以进行一些更改,但是当我再次尝试导入 Obj-C 文件时,提示不再出现。是什么原因?我什至在另一个项目中测试了同样的场景,似乎一旦我删除了 Xcode 的自动创建的桥接头,它就不会再次出现提示。为什么是这样?

回答by Shamsudheen TK

The reason of your issue is, the Xcode build settings still holds the path to auto generated Bridging Header file. You cannot get any build errors because of the header file (ProjectName-Bridging-Header.h)still exist in your project directory.

您的问题的原因是,Xcode 构建设置仍然包含自动生成的桥接头文件的路径。由于头文件(ProjectName-Bridging-Header.h)仍然存在于您的项目目录中,因此您不会收到任何构建错误。

How to resolve:

如何解决:

Click on your project target, Go to Build Settingstab (choose allinstead of basic), search for Bridging Header. You can see the Xcode generated path entry. Select it and click on delete button.

单击您的项目目标,转到Build Settings选项卡(选择all而不是basic),搜索Bridging Header。您可以看到 Xcode 生成的路径条目。选择它并单击删除按钮。

Also, make sure to delete the Xcode auto generated bridging header file (ProjectName-Bridging-Header.h)from your Xcode project directory.

另外,请确保(ProjectName-Bridging-Header.h)从 Xcode 项目目录中删除 Xcode 自动生成的桥接头文件。

Now, try to import the Obj-C file once again. You can see the prompt to create a bridging header file as expected.

现在,再次尝试导入 Obj-C 文件。您可以看到按预期创建桥接头文件的提示。

enter image description here

在此处输入图片说明

回答by Iulian Nikolaiev

File -> New File -> Header File

文件 -> 新建文件 -> 头文件

Save it as a YourApp-Bridging-Header

将其另存为 YourApp-Bridging-Header

Than go to Build Settings, find "Objective-C Bridging Header" (as previously guys told) and pass way to your Bridging Header as: YourApp/YourApp-Bridging-Header.h Where 'YourApp/' is a name of app. It could contain white space, for example 'Your App/'.

然后转到构建设置,找到“Objective-C Bridging Header”(如前所述)并通过以下方式传递到您的桥接标题: YourApp/YourApp-Bridging-Header.h 其中“YourApp/”是应用程序的名称。它可以包含空格,例如“Your App/”。

In my case in xCode 7.3.1 it works

就我而言,在 xCode 7.3.1 中它有效

回答by Kumar

There are different way of creating Bridging Header in xcode as mention/suggested above. Here I would give you the best and easiest way of creating Bridge.

正如上面提到/建议的那样,在 xcode 中有不同的创建桥接头的方法。在这里,我将为您提供创建 Bridge 的最佳和最简单的方法。

  1. Image1 shows that there is no bridging present at current point of time.
  1. Image1 显示当前时间点不存在桥接。

Image1

图片1

  1. Image2 show that I have copied a folder containing objective-c header files,after copying a popup will come on screen.
  1. Image2 显示我复制了一个包含objective-c 头文件的文件夹,复制后屏幕上会出现一个弹出窗口。

Image2

图片2

  1. Image3 is will show the popup message. But after pressing the finish button, you will notice that still there is no bridge present. for reference see image2.
  1. Image3 将显示弹出消息。但是按下完成按钮后,您会注意到仍然没有桥接。参考图片2。

Image3

图片3

  1. Now in image5&6 , I just drag and drop the objective-c header file, after doing that you will get popup message.
  1. 现在在 image5&6 中,我只是拖放 Objective-c 头文件,然后你会得到弹出消息。

Image4

图 4

  1. After pressing on finish button you get message like Would you like to configure an Objective-C bridging header?. After pressing on Yes Button you get your bridge Header,which you can see in image5.
  1. 按下完成按钮后,您会收到类似“您想配置一个 Objective-C 桥接标头吗?”的消息。. 按下 Yes 按钮后,您将获得桥标题,您可以在 image5 中看到。

Image5

图5

if you want to keep your header inside one group then use New Groupand drag&drop your file in that group.

如果您想将标题保留在一个组中,请使用新建组并将您的文件拖放到该组中。

Image6

图6

Never create any folder, or else you will get error due to that.

永远不要创建任何文件夹,否则你会因此而出错。

回答by Fonix

have a look under your project settings -> build settings, scroll down to the User-Definedsection, see if it has a key called SWIFT_OBJC_BRIDGING_HEADERand if it has a value. if its there it probably thinks you have one already, in that case just recreate the file with the same name.

查看您的项目设置 -> 构建设置,向下滚动到该User-Defined部分,看看它是否有一个被调用的键SWIFT_OBJC_BRIDGING_HEADER以及它是否有一个值。如果它在那里,它可能认为你已经有了,在这种情况下,只需重新创建具有相同名称的文件。

回答by ronan

  1. Bridge file only prompt once in a project.

  2. If you delete the file by accident, you have to build a new bridge file. It's the same.

  3. Go to File->New File->Header File, and the name should be YourProjectName-Bridging-Header, or else It can't be recognised.

  1. Bridge 文件在一个项目中只提示一次。

  2. 如果您不小心删除了该文件,则必须建立一个新的桥接文件。一样的。

  3. File->New File->Header File,名字应该是YourProjectName-Bridging-Header,否则无法识别。

回答by Unome

If you want to configure it manually simply go to Build Settings and change the selection to ALL from Basic (Default) or customized.

如果您想手动配置它,只需转到“构建设置”并将选择从“基本(默认)”或“自定义”更改为“全部”。

Because empty fields are hidden to make things easier for the average end user, if you miss the prompt to add the bridging-header you may have difficulty finding it manually. Also the search option will not include hidden fields.

因为空字段被隐藏起来,使普通最终用户的工作更容易,如果您错过了添加桥接头的提示,您可能很难手动找到它。此外,搜索选项将不包括隐藏字段。

Change to All and the Swift Compiler - General section should appear with a child setting of "Objective-C Bridging Header"

Change to All 和 Swift Compiler - General 部分应该出现“Objective-C Bridging Header”的子设置

回答by auedbaki

After dealing with this issue around one hour. I found the real issue was folder!

处理这个问题大约一个小时后。我发现真正的问题是文件夹!

Never Create/Copy folder.

从不创建/复制文件夹。

To solve the issue-

为了解决这个问题——

First Create a group of any name you like. Then copy Objective-C files into the group (not folder).

首先创建一个您喜欢的任何名称的组。然后将 Objective-C 文件复制到组(不是文件夹)中。

Then definitely you will be prompt for Bridging Header File Creation.

那么肯定会提示您创建桥接头文件。

回答by john

  1. open xcode project
  2. File -> new -> File -> if you want .swift file then click on Swift File .h file click on Header File .m file objective c file etc
  1. 打开 xcode 项目
  2. 文件 -> 新建 -> 文件 -> 如果你想要 .swift 文件然后点击 Swift 文件 .h 文件点击头文件 .m 文件目标 c 文件等