如何在Swift中为iOS创建SDK? [英] How to create SDK for iOS in Swift?

查看:231
本文介绍了如何在Swift中为iOS创建SDK?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我自己的Xcode项目,其中包含一些控制器.我想制作它的SDK,以便在另一个应用程序中使用它.在父级应用程序中,它作为子级工作.父级应用程序将与我的控制器共享一些数据,然后我的控制器对其进行处理并返回一些结果.因此,请为我提供指导.示例-付款网关SDK.我正在寻找相同的东西.

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.

推荐答案

我可以看到您添加了swift标签.在Swift中,不支持静态库,因此在将应用程序链接到库时,您必须专门使用框架(即动态库).框架类似于sdk.

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.

以下是步骤:

1)使用新建">项目"在IOS下创建框架">框架&库,选择Cocoa Touch Framework

1)Create the Framework using New > Project under IOS > Framework & Library, select Cocoa Touch Framework

2)为避免出现"ld:警告:找不到用于选项的目录...",请转到目标的构建设置"中的库搜索路径",然后删除路径.

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.

3)您不能将Objective-C与Swift混合使用,因此甚至不要考虑在代码中添加Swift-Header桥文件.

3)You can't mix Objective-C with Swift so don't even consider adding the Swift-Header bridge file in your code.

4)在某些情况下,您需要从未公开的框架中导入代码.我已经成功地使用了框架内的模块映射来处理这些情况.

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.

5)我还要在构建设置"中选择CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES = YES,以解决在框架模块中包含非模块化标头的问题".似乎可行

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

6)我确保将生成的头文件标记为Public(不是Project).点击文件,您将在检查器中的目标成员身份"下看到选择内容

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'

链接

您也可以按照本教程进行操作.由于您已经创建了项目. 创建一个框架目标,使所有源代码文件成为新目标的成员,然后将新目标作为目标添加到podfile.对于其他所有内容,本教程都应该有效.它应该可以帮助您理解步骤. 构建框架

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

这篇关于如何在Swift中为iOS创建SDK?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆