23

I added libsqlite3.0.dylib to my project, and then I tried to import using the following code:

import UIKit import sqlite3 class Dataware: NSObject { } 

But it's giving me this error:

No Such Module 'sqlite3'

0

4 Answers 4

47

Add it to your Bridging-Header.h file:

#import <sqlite3.h> 

This is the primary mechanism for importing any C-language libraries.

If you don't yet have a Bridging-Header.h file:

  1. Add a file Bridging-Header.h (or more typically (ProjectName)-Bridging-Header.h
  2. Go to the build settings tab for your project
  3. Find "Objective-C Bridging Header". The easiest way is to search for bridging.
  4. Enter the name and path for the file you created in step one. It's probably (ProjectName)/(ProjectName)-Bridging-Header.h
Sign up to request clarification or add additional context in comments.

2 Comments

Where I Add this to My Project?
I Added this File and i imported sqlite3.h but for .swift i use var dbsql=sqlite3() this line. but use of unresolved identifier 'sqite3' error is arrived
7

when one want to add sqlite to framework target, module.map is needed
since sqlite is not mapped, and to do so just:
1. create file in your project 'module/module.map'
2. create the module from the umbrella header:

 module sqlite3 [system] { header "/Applications/Xcode6-Beta5.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.0.sdk/usr/include/sqlite3.h" link "sqlite3" export * } 

*change the Xcode6-Beta5.app in the path to right one
3. connect the map file to you project, search for 'import paths' in 'Build Settings'and put the full path to the module file

5 Comments

this solution worked for me when tried to add sqlite to my swift framework
Hi @ben. Could you please elaborate your answer. I am not getting how to add a new module
Hi @RatikantaPatra, to add new module map, you need to: [1]create file called module.map [2]add the wanted module info (like in my answer) [3]in Xcode Go to Build Settings->set Swift Compiler->Search Paths->Import Paths to the directory that you put the module.map file in
Is it possible to change the absolute path in that file to something like $(SDKROOt)? Do you know if module.map files support something like that?
@StefanArentz Module map files do not, but you can use an xcconfig file to reference different MODULEMAP_FILE paths per platform. See my answer to another question, or my SQLite.swift framework (on the swift-1-2 branch) for examples.
5

We need to import the header files for SQLite3 into the view controller so that the compiler can see the function and other definitions that make up the API.

There is no way to directly import the header file into Swift code, because the SQLite3 library is not packaged as a module.

The easiest way to deal with this is to add a bridging header to the project. Once you have a bridging header, you can add other header files to it, and those header files will be read by the Swift compiler. There are a couple of ways to add a bridging file. We’ll use the simpler of the two, which is to temporarily add an Objective-C class to the project. Let’s do that now.

File ➤ New ➤ File.... In the iOS section of the dialog, choose Cocoa Touch Class and press Next. Name the class Temporary, make it a subclass of NSObject, change the language to Objective-C, and press Next. In the next screen, press the Create button. When you do this, Xcode will pop up a window asking whether you want to create a bridging header. Press Yes. Now, in the Project Navigator, you’ll see the files for the new class (Temporary.m and Temporary.h) and the bridging header, which is called SQLite Persistence-Bridging-Header.h. Delete the Temporary.m and Temporary.h files—you don’t need them anymore. Select the bridging header to open it in the editor, and then add the following line to it:

#import < sqlite3.h>

Now that the compiler can see the SQLite3 library and header files, we can write some more code in ViewController.swift

That's it!

Comments

3

Hi Please follow these steps

In xcode 8.3.3 using swift 3

  1. Go to Build Phases tab
  2. Go to Link Binary with Libraries sub tab.

    (a) Click + button to add sqlite framework then search for sqlite then you can see libsqlite3.0.tbd and libsqlite3.tbd

    (b) Then select only libsqlite3.tbd(Don't add both because the compiler can not find sqlite3 stuct when you declare in viewController)

  3. Then Add Bridging-Header.h file (because sqlite is not written in swift)

  4. Bridging name should be your Projectname-Bridging-Header.h file (Just for naming convention, not mandatory)
  5. Write #import <sqlite3.h> in your Bridging-Header file
  6. Go to build settings tab

    (a) Under the build settings tab search for Swift Compiler - General option and set YES to Install Objective-C compatibility Header

    (b) Set your name and path for the header file in Objective-C Bridging Header option (Or you can simply drag the bridging header file)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.