简体   繁体   中英

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

I converted my entire Objective-C framework to Swift . After building it, when I check the framework's Header files, it is still displaying the old Objective-c functions.
I deleted all the Objective-C files from the framework project. 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?

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.

Just make sure the search paths don't look for old Obj-C stuff. Be careful of recursive searches like 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. Therefore, the class you migrate can't have any Objective-C subclasses.

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.

To make a Swift class available in Objective-C, make it a descendant of an Objective-C class.

Command-click a Swift class name to see its generated header.

Option-click a symbol to see implicit information about it, like its type, attributes, and documentation comments.

from: 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.

How can you see "Header" files in Swift based framework even after removing Obj C files. 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))

禁用模块

  • Make sure the Swift version is set (Swift Language Version)

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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