xcode 如何在 Swift 中为 iOS 创建 SDK?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46127937/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to create SDK for iOS in Swift?
提问by Mayur Shinde
I have my own Xcode project which contains some controllers. I want to make its SDK, for use it in another application. In parent application it works as child. Parent app will share some data with my controller and my controller works on it and gives back some result. So kindly guide for me. Examples are - Payment Gateway SDK's. I am looking for the same.
我有自己的 Xcode 项目,其中包含一些控制器。我想制作它的 SDK,以便在另一个应用程序中使用它。在父应用程序中,它作为子应用程序工作。父应用程序将与我的控制器共享一些数据,我的控制器对其进行处理并返回一些结果。所以请为我指导。示例是 - 支付网关 SDK。我正在寻找相同的。
回答by cole
I can see you add tag for swift. In Swift, static libraries are not supported, so you must exclusively use a framework (aka dynamic library) when linking an app to a library. Framework is similar to sdk.
我可以看到您为 swift 添加了标签。在 Swift 中,不支持静态库,因此在将应用程序链接到库时,您必须专门使用框架(又名动态库)。框架类似于sdk。
Here are the steps:
以下是步骤:
1)Create the Framework using New > Project under IOS > Framework & Library, select Cocoa Touch Framework
1)在IOS下的New > Project > Framework & Library创建Framework,选择Cocoa Touch Framework
2)To avoid the "ld: warning: directory not found for option..." goto Library Search Paths in Build Settings for your target and delete the paths.
2)为了避免“ld:警告:找不到选项的目录...”转到目标构建设置中的库搜索路径并删除路径。
3)You can't mix Objective-C with Swift so don't even consider adding the Swift-Header bridge file in your code.
3)您不能将 Objective-C 与 Swift 混合使用,因此甚至不要考虑在您的代码中添加 Swift-Header 桥接文件。
4)There are some cases in swift where you need to import code from unexposed Frameworks. I've successfully used the module-map inside the framework to deal with these case.
4) 在 swift 中有一些情况你需要从未公开的框架中导入代码。我已经成功地使用框架内的模块映射来处理这些情况。
5)I also select CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES = YES in the Build Settings to solve 'include of non-modular header inside framework module'. That seems to work
5)我还在构建设置中选择 CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES = YES 来解决“框架模块中包含非模块化头文件”的问题。这似乎有效
6)I make sure that the header file that gets generated is marked as Public (not Project). Click on the file and you'll see the selection in the inspector under 'Target Membership'
6)我确保生成的头文件被标记为公共(不是项目)。单击该文件,您将在“目标成员资格”下的检查器中看到选择
Also you can follow this tutorial. Since you have already created project. Create a framework target, make all source code files a member of the new target, add the new target as target to the podfile. For everything else the tutorial should work. It should help you in understanding the steps. Build framework
您也可以按照本教程进行操作。由于您已经创建了项目。创建框架目标,使所有源代码文件成为新目标的成员,将新目标作为目标添加到 podfile。对于其他一切,教程应该有效。它应该可以帮助您理解这些步骤。 构建框架