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

Make FluentSQLite usable on iOS #7

Closed
twof opened this Issue Apr 2, 2018 · 9 comments

Comments

4 participants
@twof
Copy link
Member

twof commented Apr 2, 2018

The two most popular options for persistence on iOS (Realm and Core Data), both rely heavily on Objective-C, however, SQLite is available. I think there is a good opportunity to not only have a Swift based persistence layer on iOS, but also promote code sharing between Vapor servers and iOS clients.

Concept:

// Shared models package, imported by both client and server
class User: Codable {
  let id: Int?
  let name: String
  let age: Int
}

// Client
extension User: SQLiteModel, Migration {}

// Server
extension User: PostgresModel, Migration {}

I haven't heavily investigated what is keeping users from utilizing FluentSQLite in their iOS apps, but the first thing that comes to mind is the Console package's use of Process()

@kdawgwilk

This comment has been minimized.

Copy link

kdawgwilk commented Apr 2, 2018

Would also need to support CocoaPods and Carthage unless we want to hold this off until WWDC and make a bet that SPM will finally be integrated into Xcode

@twof

This comment has been minimized.

Copy link
Member Author

twof commented Apr 2, 2018

Technically it's possible to use SPM with iOS apps if we wanted to for testing, but it's really hacky and I'd definitely advise against it in production

https://www.ralfebert.de/ios-examples/xcode/ios-dependency-management-with-swift-package-manager/

Got a macOS Cocoa app running with FluentSQLite using that method

@twof

This comment has been minimized.

Copy link
Member Author

twof commented Apr 6, 2018

Good news! Process was the only thing preventing this package from being compiled for iOS. It's used in one method in Console and extended in Core, and neither that method nor that extension are used in this package. After wrapping those two in #if os(OSX), the package compiles just fine. Trying to figure out how to import it into an iOS project now.

@rafiki270

This comment has been minimized.

Copy link

rafiki270 commented Apr 6, 2018

Well, that’s simple ... convert this and all subsequent projects (might not be necessary) and make them each an xcode project ... adding that I think will be the biggest challenge to get through the NIO guys and Tanner ... ;) unless we’ll get lucky this WWDC

@twof

This comment has been minimized.

Copy link
Member Author

twof commented Apr 6, 2018

Forked, built using iOS 11.3, and imported the framework to a test project using the instructions here

https://stackoverflow.com/a/40990828/3908168

Cleaned and built, but I'm getting error: missing required module 'CNIOAtomics'. Is there anything special about that file?

@kdawgwilk

This comment has been minimized.

Copy link

kdawgwilk commented Apr 6, 2018

Its a swift wrapper around a c library so that one might be tricky, you might have to do some header/modulemap magic to get that to work

@tanner0101 tanner0101 added this to the 3.0.0 milestone Jun 15, 2018

@tanner0101 tanner0101 self-assigned this Jun 15, 2018

@tanner0101

This comment has been minimized.

Copy link
Member

tanner0101 commented Jun 15, 2018

vapor/sqlite now uses the SQLite3 module available on iOS and macOS (still uses CSQLite on Linux).

screen shot 2018-06-14 at 9 37 39 pm

Tests appear to be passing when run on iPhone X simulator. Let me know if you guys manage to get it working in a real iOS project. Closing this issue for now. 👍

@tanner0101 tanner0101 closed this Jun 15, 2018

@twof

This comment has been minimized.

Copy link
Member Author

twof commented Jun 15, 2018

Were you also seeing these warnings?
screen shot 2018-06-15 at 10 03 33 am
Going to try adding it to an iOS project anyway

@tanner0101

This comment has been minimized.

Copy link
Member

tanner0101 commented Jun 15, 2018

@twof I didn't see those in my build. Maybe the NIO guys would know more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment