-
-
Save zgchurch/3bac5443f6b3f407fe65 to your computer and use it in GitHub Desktop.
// 1. Create this file in your Xcode project | |
// 2. Go to "Build Settings" and find "Objective-C Bridging Header." Use the search bar to find it quickly. | |
// 3. Double-click and type "BridgingHeader.c" | |
// If you get "Could not import Objective-C Header," try "my-project-name/BridgingHeader.h" | |
// 4. Go to "Build Phases," "Link Binary With Libraries," and add libsqlite3.0.dylib | |
#include <sqlite3.h> |
import Foundation | |
var db: COpaquePointer = nil; | |
if sqlite3_open("/Users/zchurch/Code/testapp/db/development.sqlite3", &db) != SQLITE_OK { | |
println("Failed to open file") | |
exit(1) | |
} | |
var sql = "SELECT * FROM schema_migrations" | |
var statement:COpaquePointer = nil | |
var tail: CString = "" | |
if sqlite3_prepare_v2(db, sql.bridgeToObjectiveC().UTF8String, sql.lengthOfBytesUsingEncoding(NSUTF8StringEncoding).bridgeToObjectiveC().intValue, &statement, &tail) != SQLITE_OK { | |
println("Failed to prepare statement") | |
exit(1) | |
} | |
func print_row(s: COpaquePointer) { | |
for i in 0..sqlite3_column_count(s) { | |
switch sqlite3_column_type(s, i) { | |
case SQLITE_INTEGER: | |
var r = sqlite3_column_int(s, i) | |
case SQLITE_TEXT: | |
var r = CString(sqlite3_column_text(s, i)) | |
println("String: \(r)") | |
default: | |
println("Other column type") | |
} | |
} | |
} | |
var complete = false | |
while complete == false { | |
switch sqlite3_step(statement){ | |
case SQLITE_DONE: | |
println("Done executing statement") | |
case SQLITE_ROW: | |
println("Row") | |
print_row(statement) | |
default: | |
println("Other") | |
complete = true | |
} | |
} | |
See the comment at the top of BridgingHeader.h - get to build settings by clicking on your project in the left project drawer with the "Project Navigator" open (Command + 1)
// 1. Create this file in your Xcode project
// 2. Go to "Build Settings" and find "Objective-C Bridging Header." Use the search bar to find it quickly.
// 3. Double-click and type "BridgingHeader.c"
// If you get "Could not import Objective-C Header," try "my-project-name/BridgingHeader.h"
// 4. Go to "Build Phases," "Link Binary With Libraries," and add libsqlite3.0.dylib
Hi, zgchurch , i want to know about this line [ // 3. Double-click and type "BridgingHeader.c" ] , "BridgingHeader.c" or "BridgingHeader.h" .
where is BridgingHeader.c?
Hello Zach,
thanks for your code ideas. I am using them in listing the backup files of iOS devices, see https://github.com/ekuester/List-ManifestDB-From-iOSBackup. Regards, Erich Kuester
Hi zgchurch! so in this way where and how i can setting file bridgingheader.h in my swift project