iOS Tutorial Swift libraries

Erel

Administrator
Staff member
Licensed User
B4i v3.60 adds support for libraries written in Swift and compiled as frameworks.

This is an important feature as many (probably most) of the new open source projects are written in Swift.
The B4i wrapper is written in Objective C. You can see an example here: https://github.com/AnywhereSoftware/B4i_iSwiftyButton (note the ~dependson attribute).

Using a Swift library is not different than using an Objective C library. There are however a couple nuances that you should be familiar with:
1. The minimum supported iOS version is 8. You need to add:
B4X:
#MinVersion: 8
2. Swift runtime libraries - All applications with Swift code depend on Swift runtime libraries. They are added automatically during compilation. The runtime size is about 8mb.
Note that the size of the ipa file, when you compile with a store provision profile in release mode, will be about 35mb. Still the app size when installed on the device will be around 8mb.
Example of B4i app with Swift library: https://itunes.apple.com/us/app/b4i-coordinates-calculator/id915366768?mt=8

3. Simulator not supported for now.
 

Erel

Administrator
Staff member
Licensed User
I will clarify the simulator issue.

If you use a "fat" framework, that is a framework that includes binaries for i386 as well as the arm binaries, then the ipa file will be rejected when you try to submit it. The reason is that swift libraries are dynamic libraries and unlike regular static libraries they are embedded as-is in the app. The app store verification process rejects non-arm binaries.

You can use a fat framework during development and switch to an arm only framework before submitting it to the store.

In the future the B4i builder will automatically strip fat dynamic frameworks when you create a store build.
 

Alberto Iglesias

Well-Known Member
Licensed User
Somebody has a complete project for XCODE and SWIFT to create a simple library?

with some dependency and event returned to B4i?

Thanks
 
Top