简体   繁体   English

将Objective-C框架转换为Swift-头文件仍显示Objective-C函数

[英]Converting an Objective-C framework to Swift - Header files still displaying Objective-C functions

I converted my entire Objective-C framework to Swift . 我将整个Objective-C框架都转换为Swift After building it, when I check the framework's Header files, it is still displaying the old Objective-c functions. 构建它之后,当我检查框架的Header文件时,它仍显示旧的Objective-c函数。
I deleted all the Objective-C files from the framework project. 我从框架项目中删除了所有Objective-C文件。 I have tried cleaning and building the project. 我曾尝试清洁和建设该项目。 But with no success. 但是没有成功。

You deleted the Objective-C files from the Xcode project, but did you also remove them from the file system and any source control you might be using? 您已从Xcode项目中删除了Objective-C文件,但是还从文件系统以及您可能正在使用的任何源代码管理中删除了它们吗?

Also, your Build Settings in your Xcode project can be searching for library/header files even after you've removed them from explicit inclusion in the Project Navigator in Xcode. 同样,即使您已将Xcode项目中的“构建设置”从显式包含在Xcode的项目导航器中明确删除后,也可以在它们中搜索库/头文件。

Just make sure the search paths don't look for old Obj-C stuff. 只要确保搜索路径不会寻找旧的Obj-C东西即可。 Be careful of recursive searches like MyXcodeProject/** . 注意诸如MyXcodeProject/**类的递归搜索。 The ** will recursively search all subfolders and their subfolders for things to include. **将递归搜索所有子文件夹及其子文件夹以查找要包含的内容。

Better to specify folders directly in the search paths if you can. 如果可以的话,最好直接在搜索路径中指定文件夹。 If you know you don't need search paths, you can just clear them all. 如果您知道不需要搜索路径,则只需清除它们即可。

在此处输入图片说明

...although, you may want to leave the default exclusions in place: ...尽管,您可能希望保留默认排除项:

在此处输入图片说明

Remember that you can't subclass a Swift class in Objective-C. 请记住,您不能在Objective-C中继承Swift类。 Therefore, the class you migrate can't have any Objective-C subclasses. 因此,您迁移的类不能包含任何Objective-C子类。

Once you migrate a class to Swift, you must remove the corresponding .m file from the target before building to avoid a duplicate symbol error. 将类迁移到Swift后,必须在构建之前从目标中删除相应的.m文件,以避免重复的符号错误。

To make a Swift class available in Objective-C, make it a descendant of an Objective-C class. 为了使Swift类在Objective-C中可用,使其成为Objective-C类的后代。

Command-click a Swift class name to see its generated header. 按住Command键并单击Swift类名称,以查看其生成的标头。

Option-click a symbol to see implicit information about it, like its type, attributes, and documentation comments. 按住Option键单击一个符号可以查看有关它的隐式信息,例如其类型,属性和文档注释。

from: https://developer.apple.com/documentation/swift/migrating_your_objective-c_code_to_swift 来自: https : //developer.apple.com/documentation/swift/migrating_your_objective-c_code_to_swift

Also, delete your DerivedData, do a clean build and restart the xCode. 另外,删除您的DerivedData,执行干净的构建并重新启动xCode。

How can you see "Header" files in Swift based framework even after removing Obj C files. 即使删除了Obj C文件,如何在基于Swift的框架中也能看到“ Header”文件。 Definitely there's the build issue. 肯定存在构建问题。 If build is proper, then you are not referring/using to the right framework (in the app) after building it. 如果构建正确,则构建后您将不会引用/使用正确的框架(在应用程序中)。 This is most common mistake that I observed with many developers. 这是我在许多开发人员中发现的最常见的错误。

Maybe this can help, try it on your framework's Target Build Settings : 也许可以帮上忙,在您的框架的“目标构建设置”上尝试一下:

  • Disable modules (Enable modules (C and Objective-C)) 禁用模块(启用模块(C和Objective-C))

禁用模块

  • Make sure the Swift version is set (Swift Language Version) 确保设置了Swift版本(Swift语言版本)

在此处输入图片说明

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

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