Skip to content

Update multiplatform-ktor-sqldelight.md #250

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions topics/development/multiplatform-ktor-sqldelight.md
Original file line number Diff line number Diff line change
Expand Up @@ -933,10 +933,14 @@ The Kotlin Multiplatform wizard generates an iOS project that is already connect
is exported with the name specified in the `shared/build.gradle.kts` file (`baseName = "Shared"`), and imported
using a regular `import` statement: `import Shared`.

### Turn off static linking
### Linking sqlite

On iOS, the Xcode build tools need to "link" to the system sqlite library. There are two basic ways to do that.

#### Turn off static linking

The Kotlin Multiplatform wizard generates projects set up for static linking of iOS frameworks.
To use the SQLDelight library, allow the iOS framework to link dynamically.
The pros and cons of static vs dynamic linking are only important for production apps. To make linking simple for now, link your framework dynamically.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These docs are a bit out of date for another reason: in recent versions of KMP, dynamic linking is already the default. So it makes no sense to have a section titled "Turn off static linking".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you consider "recent versions of KMP"? Most of the samples in the docs are based on the KMP wizard, and the latest project generated there still has isStatic = true in that section.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm talking about the default for the Kotlin gradle plugin, not the KMP wizard.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. The section is explicitly written in the context of the tutorial and the wizard, so I don't think there should be any confusion here.

It was pointed out to us that one can remove the isStatic field rather than set it to false since this is the default value, and maybe that's what we should advise here. I think we opted for clarity last time, but I'm not so sure now.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, given this is written in the context of the wizard which sets it to true, it makes sense.


To do that, open the `shared/build.gradle.kts` file and change the `isStatic` property of the `iosTarget.binaries.framework`
block to `false`:
Expand All @@ -959,6 +963,12 @@ kotlin {
```
{initial-collapse-state="collapsed" collapsed-title="isStatic = false"}

#### Add the sqlite linker flag to Xode

The first option, "Turn off static linking", is generally simpler. However, to build with a static framework, add the linker flag in Xcode config.

In Xcode, find the project, and open “Build Settings”. Search for "Other Linker Flags", and add `-lsqlite3`.

### Prepare a Koin class for iOS dependency injection

To use Koin classes and functions in Swift code, create a special `KoinComponent` class and declare the Koin
Expand Down