It is very difficult for me to structure a mixed iOS application for Swift / Obj-C to avoid build errors after converting classes to Swift.
This is a problem with a very brief break in the Swift documentation:
If you use your own Objective-C types in your Swift code, be sure to import the Objective-C headers for these types before importing the Swift generated header into the Objective-Cm file that you want to get the Swift code for.
Firstly, although the documentation pretty explicitly states that the -Swift.h file is in .m files, it very often refers to types from classes that are now based on Swift code in .h files of Obj-C classes, so I have to import -Swift.h to .h files most of the time. It seems strange to contradict the document, but I donβt see how else these headers will be built, and this worked most of the time.
The real problem occurs when the generated -Swift.h file contains compiler errors, such as
Unknown type name 'SomeObjCClass'
The only way to overcome these errors is to make sure that the specified class reaches the -Swift.h file, as the documentation suggests, but is unable to figure out how the build order is determined. I find I am importing all kinds of Obj-C headers throughout the project until the generated header, until I get the working assembly. There is no way for this to be a good way, but I donβt know the right way.
How to determine where the -Swift.h header -Swift.h included for the first time, so that I can get all the necessary Obj-C classes imported just above it, and then it will be enough so that only -Swift.h can be imported in the remaining places as necessary, or should its prerequisites be collected above it every time (which, I believe, is not much different from what I'm doing now)?
source share