Swift 2 Support
I know it's early, but I'm playing with Swift 2 and Xcode 7. This is not compiling anymore. Do you know how to fix it?
internal let SQLITE_STATIC = sqlite3_destructor_type(COpaquePointer(bitPattern: 0)) internal let SQLITE_TRANSIENT = sqlite3_destructor_type(COpaquePointer(bitPattern: -1))
Swift 2 is going to be a big adjustment. You should be able to update the above with:
internal let SQLITE_STATIC = unsafeBitCast(0, sqlite3_destructor_type.self)
internal let SQLITE_TRANSIENT = unsafeBitCast(-1, sqlite3_destructor_type.self)
But even then there are some segfaults to deal with. Regardless, there are a lot of opportunities with Swift 2 to reconsider flow control, etc. I'm going to start working on a branch and push preliminary, experimental stuff when it's ready.
Me too... Hope you find a solution for it as I would like to continue working with Swift2.
Update: I'm making good headway but the Swift 2 changes require a rethinking and rewriting of a lot of things—a net win in the end but things are going a bit slower and at a time where I don't have a lot of free time. I'll try to push a WIP soon.
@stephencelis encouraging to hear you're making progress! Great stuff!
Is there anything that can be done to help you? I'm sure that there are some people who can pick up some slack for you. Might be easier to break it up into a series of features merging into a swift_2.0 branch?
@danthorpe I'll try to push a WIP this weekend. I started with a new from-scratch project just to get my bearings and have been copy-pasting and re-writing as I go, so it's not and won't be in working order quite yet, but you'll be able to get a feel for the changes if you dive in.
hi @stephencelis,
if you need some help, just let us know. I'd love to have SQLite working on Swift2
@stephencelis Hey Stephen, any update? I'm happy to help and/or give feedback.
@stephencelis Hey i can help u too :dancer:
That took longer than expected :sweat_smile:
Please see https://github.com/stephencelis/SQLite.swift/pull/154 for progress. It's getting there, but I'll probably need some more dedicated time to push it to completion and current feature parity.
Wow! Lots of changes! Great stuff @stephencelis - lots of stuff for us to look though 😃
The PR (#154) should basically be at feature parity with the Swift 1.2 version now with a few small exceptions related to more complicated querying (table/column aliasing, selecting/joining on scalar queries, reordering). The documentation still needs to be updated. You should be able to start migrating your apps, though.
I should be on target to have things ready for the GM.
Yes!! Thanks for all your efforts @stephencelis!
Thank you for the Swift 2 support, it is awesome. I do have one issue that I am experiencing and not sure if it belongs here or as a separate issue. Also not sure if I am just missing something but figured I would put it here:
I have the following code to query one of my tables:
static func findAll() throws -> [SelectableItem]? {
guard let DB = SQLiteDataStore.sharedInstance.DB else {
throw DataStoreError.Datastore_Connection_Error
}
var retArray = [SelectableItem]()
do {
let items = try DB.prepare(table.order(defaultUnit))
for item in items {
retArray.append((key: item[key], id: item[id], displayName: item[displayName]))
}
return retArray
} catch _ {
throw DataStoreError.Search_Error
}
}
The line:
let items = try DB.prepare(table.order(defaultUnit))
orders the values ascending which is what I would expect. When I change the line to:
let items = try DB.prepare(table.order(defaultUnit.desc))
to order the results descending I do not get any results returned. Just to see what I would get, I also change the code to this:
let items = try DB.prepare(table.order(defaultUnit.asc))
it also do not return any values.
Looking at the playground that comes with the code, it looks like this should work. I am doing something wrong? Thanks,
@hoffmanjon This was a bug. I've pushed a fix.
Works great, thank you for the quick turn around.
This is an awesome library!!! And I've just upgraded to XC7 Swift 2 & having multiple problems. I'm a noob & hoping you can tell me how to fix it... I went into my cloned git repo & ran: git checkout swift-2 that worked fine and so I ran "git pull" which also ran fine but how can I be sure that xcode is using this current repo, rather than files that were "copied (if needed)" into my project?? I clicked on the SQLite.xcodeproj and rebuilt it successfully, but every time I try to run my project, it crashes with:
fatal error: 'try!' expression unexpectedly raised an error: SQL logic error or missing database: file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-700.0.57.3/src/swift/stdlib/public/core/ErrorType.swift, line 50
all tips appreciated!!
Doing some housekeeping and noticed this was still open! Closing! :smile: