Run your SQLite.Swift Apps on Android without any code change

At SCADE, we want to make sure that all your favourite Swift data persistence options are available on both Android and iOS without a need for code changes. This article describes the SQLite.Swift support.

SQLite.Swift is an awesome library to make working with the SQLite database even easier. It provides utility classes to easily implement data persistency on iOS using Swift. Due to the availability of Swift Foundation for Android and static C library linking support thanks to SCADE, SQLite.Swift is now available for Swift for Android as well.

The design goal of the implementation is simple: Run your SQLite.Swift code on Android without any code change. To demonstrate this, we are running the sample code from github https://github.com/stephencelis/SQLite.swift .

1. Add SQLite libraries

The SQLite functionality is implemented as static C libraries that need to be embedded in the app for Android. On iOS, SQLite is part of iOS and doesn’t need to be added. We add the libraries into the lib directory of the newly created project:

Adding SQLite binaries

2. Add SQLite.Swift package dependency

SQLite.Swift is available as an SPM package. We added support of SPM in SCADE 0.9.8.x and the support is straightforward. Just specify URL, from label and the name of the linked library in the build file of your SCADE project:

Specify SPM dependancy

3. Copy SQLite.Swift sample code from SQLite.Swift website

Now, to demonstrate the fact that SQLite.Swift runs without any code change, copy the comprehensive example from the SQLite.Swift website (https://github.com/stephencelis/SQLite.swift#usage) into the main page of the app:

Source code copied 1:1 into SCADE app main class

4. Run the unmodified code on Android

You can now press the compile button, and the compiled Android app shows up in the Android emulator :-).

Viva Swift!
Your SCADE team

www.scade.io

Links

Cross Platform App Development with Apple Swift

Written by

We use Medium to share our journey of creating what we hope will become the #1 next generation platform for native, cross platform app development www.scade.io

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade