Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS Usage Instructions #427

Open
louwers opened this issue Mar 29, 2024 · 2 comments
Open

iOS Usage Instructions #427

louwers opened this issue Mar 29, 2024 · 2 comments

Comments

@louwers
Copy link
Contributor

louwers commented Mar 29, 2024

There is an XCFramework that is distributed, but it is unclear if it can actually be used on iOS.

@michaelmedellin
Copy link

@louwers were you able to make any headway on this?

@michaelmedellin
Copy link

michaelmedellin commented Jul 20, 2024

@louwers progress on my part.

  1. Download the latest release and extract the framework from crsqlite-ios-dylib.xcframework.tar
  2. Add the framework to your project
    • Under project build phases, make sure the framework is in included under the Embed Frameworks phase
    • Under the General tab, make sure the framework is in the Frameworks, Libraries, and Embedded Content list
  3. Install a custom sqlite that allows for loading extensions. The native iOS Sqlite3 library does not allow extensions to be loaded at all so you need to bring in your own via another path. The sqlite3 library via Cocoapods works.
  4. You'll need a method to initialize the extension in the app. For example in a C file in the project:
#include "crsqlite-init.h"
#include "sqlite3.h"

int sqlite3_crsqlite_init(sqlite3 *db, char **pzErrMsg,
                          const sqlite3_api_routines *pApi);

int crsqlite_init_from_swift() {

    return sqlite3_auto_extension((void *)sqlite3_crsqlite_init);
}

NOTE: will need corresponding header file and bridging header in the project.

  1. You'll then just need to call crsqlite_init_from_swift() from your app to initialize.

@tantaman has a scaffold in the https://github.com/tantaman/xcode-starter repository. However, he's not using the framework in that example.

One of the issues I ran into is that I'm using GRDB as a SQLite interface for Swift, rather than the C sqlite API. Prepackaged GRDB uses the iOS shipped version of sqlite3 which won't load extensions (GRDB cannot use the Cocoapods sqlite3 package AFAIK). GRDB does allow for custom sqlite builds but the build of sqlite that GRDB compiles actually doesn't allow extensions either. So you need to change the compilation configuration to remove this flag and then it'll work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants