0

how to overcome this error

  func selectFunc(){
    var selectQuery="select * from EmployeInfo"
    var cSql:CString = selectQuery.bridgeToObjectiveC().cStringUsingEncoding(NSUTF8StringEncoding)
    var result:CInt=0

    var stmt:COpaquePointer = nil
    result = sqlite3_prepare_v2(appDelegate.database, cSql, -1, &stmt, nil);
    if result != SQLITE_OK

error occurred use of undeclared CString.how to overcome this error

1 Answers1

2

In older Swift versions (before Xcode 6 beta 6), a Swift String had explicitly to be converted when passed to a C function taking a const char * argument, as in your code.

This is no longer necessary. The CString type and the bridgeToObjectiveC() method do not exist anymore.

The current Swift compiler does the conversion automatically (compare String value to UnsafePointer<UInt8> function parameter behavior) and you can just write

let selectQuery = "select * from EmployeInfo"
var stmt : COpaquePointer = nil
let result = sqlite3_prepare_v2(appDelegate.database, selectQuery, -1, &stmt, nil)
Community
  • 1
  • 1
Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382