How can I add forward class references used in the -Swift.h header?

后端 未结 2 1744
说谎
说谎 2020-11-29 07:33

I\'m integrating Swift code into a large Objective-C project, but I\'m running into problems when my Swift code refers to Objective-C classes. For example, suppose I have:

相关标签:
2条回答
  • 2020-11-29 08:06

    This is a little silly, but it sounds like your "workaround" is what Apple intended, at least for now. From the interoperability guide:

    If you use your own Objective-C types in your Swift code, make sure to import the Objective-C headers for those types prior to importing the Swift generated header into the Objective-C .m file you want to access the Swift code from.

    In this devforums thread, someone mentioned they already filed a bug in Radar. You probably should too.

    0 讨论(0)
  • 2020-11-29 08:24

    You can create another header file that forward declares or imports the necessary classes, and then imports ProjectName-Swift.h. For example, create a file named ProjectName-Swift-Fixed.h with the contents:

    // ProjectName-Swift-Fixed.h
    
    // Forward declarations for property classes
    @class DeletionWorkflow;
    
    // Imports for superclasses
    #import "MyTableViewController.h";
    
    #import "ProjectName-Swift.h"
    

    Then, instead of #import "ProjectName-Swift.h" in your codebase, use #import "ProjectName-Swift-Fixed.h.

    0 讨论(0)
提交回复
热议问题