Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create SDK for iOS in Swift?

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.

like image 304
Mayur Shinde Avatar asked Sep 09 '17 06:09

Mayur Shinde


1 Answers

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.

Here are the steps:

1)Create the Framework using New > Project under IOS > Framework & Library, select 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.

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

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)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)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'

Link

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

like image 141
cole Avatar answered Oct 14 '22 17:10

cole