iOS Tutorial Swift libraries

Discussion in 'iOS Tutorials' started by Erel, Jan 29, 2017.

  1. Erel

    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:
    Code:
    #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.
     
    JanPRO likes this.
  2. JanPRO

    JanPRO Well-Known Member Licensed User

    Thank you for this important feature.
    After creating a framework with both architectures it seems to be possible (see attached picture).

    Jan
     

    Attached Files:

  3. Erel

    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.
     
    netkomm and JanPRO like this.
  4. Alberto Iglesias

    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
     
  5. Erel

    Erel Administrator Staff Member Licensed User

  6. Alberto Iglesias

    Alberto Iglesias Well-Known Member Licensed User

    huuummm.. OK. I will convert it to objectiveC...
    thanks @Erel
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice