如何使用Objectivec文件和Swift文件创建框架

时间:2023-01-17 13:10:54

I have a Xcode project with Obiective-c files and swift files, Now i want to create a framework with both classes, Is this possible ?

我有一个带有Obiective-c文件和swift文件的Xcode项目,现在我想用这两个类创建一个框架,这可能吗?

1 个解决方案

#1


6  

Yes, this is straightforward and the process is documented by Apple. Please read "Swift and Objective-C in the Same Project" with thought and you'll be wiser (the section "Importing Code from Within the Same Framework Target" covers importing Objective-C in Swift from the same target, and the other way). Briefly…

是的,这很简单,Apple会记录这个过程。请仔细阅读“同一项目中的Swift和Objective-C”,您将更加明智(“从同一框架目标中导入代码”一节涵盖从同一目标导入Swift中的Objective-C,另一种方式)。简单地说...

  • For framework targets you don't need to create a bridging header to make your Objective-C importable to Swift, you just need to #import those headers you want visible to Swift in the framework's umbrella header. For that to work, the header needs to be marked public.
  • 对于框架目标,您不需要创建桥接头来使您的Objective-C可导入Swift,您只需要在框架的伞头中#import那些您希望Swift可见的头。要使其工作,标题需要标记为public。

  • For Swift to be importable in Objective-C in the same framework target, make sure "Defines Module" is toggled on for the target, and in the files where you need to reference the Swift types, do an import in the style #import <ProductName/ProductModuleName-Swift.h>. If I recall this right, the Swift types / methods / properties you want to access from Objective-C will need to have been declared public for it to be accessible to Objective-C code even if it's in the same target.
  • 要使Swift可以在同一框架目标中的Objective-C中导入,请确保为目标切换“定义模块”,并在需要引用Swift类型的文件中,以#import <样式导入产品名称 productmodulename-swift.h> 。如果我记得这一点,那么你想要从Objective-C访问的Swift类型/方法/属性需要被公开,以便Objective-C代码可以访问它,即使它在同一个目标中也是如此。

#1


6  

Yes, this is straightforward and the process is documented by Apple. Please read "Swift and Objective-C in the Same Project" with thought and you'll be wiser (the section "Importing Code from Within the Same Framework Target" covers importing Objective-C in Swift from the same target, and the other way). Briefly…

是的,这很简单,Apple会记录这个过程。请仔细阅读“同一项目中的Swift和Objective-C”,您将更加明智(“从同一框架目标中导入代码”一节涵盖从同一目标导入Swift中的Objective-C,另一种方式)。简单地说...

  • For framework targets you don't need to create a bridging header to make your Objective-C importable to Swift, you just need to #import those headers you want visible to Swift in the framework's umbrella header. For that to work, the header needs to be marked public.
  • 对于框架目标,您不需要创建桥接头来使您的Objective-C可导入Swift,您只需要在框架的伞头中#import那些您希望Swift可见的头。要使其工作,标题需要标记为public。

  • For Swift to be importable in Objective-C in the same framework target, make sure "Defines Module" is toggled on for the target, and in the files where you need to reference the Swift types, do an import in the style #import <ProductName/ProductModuleName-Swift.h>. If I recall this right, the Swift types / methods / properties you want to access from Objective-C will need to have been declared public for it to be accessible to Objective-C code even if it's in the same target.
  • 要使Swift可以在同一框架目标中的Objective-C中导入,请确保为目标切换“定义模块”,并在需要引用Swift类型的文件中,以#import <样式导入产品名称 productmodulename-swift.h> 。如果我记得这一点,那么你想要从Objective-C访问的Swift类型/方法/属性需要被公开,以便Objective-C代码可以访问它,即使它在同一个目标中也是如此。