Want to use sqlite3.h in iOS application - objective-c

I am responsible for converting an application from Objective-C to Swift. One of the objective c files called 'database' imports file called sqlite3.h. Now I did not convert database.h and database.m to Swift. Instead I created an Objective-C bridging header that exposed the database code to the Swift files. However the database header file imports a file called sqlite3.h. So first I linked a library to my project called libsqlite3.dylib as I believed this library contains the sqlite3.h file. But I cannot view any header files the library contains.
So do I just need to include the libsqlite3.dylib in my objective-c bridging header file, and if so whats the syntax? Or do i need to download the sqlite3.h header file, and if so where can I get the code from or download it from?

Libraries do not contain header files (i.e. there is no header inside a dylib file).
In database.h (or .m), there is a line that looks like this:
#import <sqlite3.h>
Right-click on it and choose "Jump to definition" -- it should take you to the file. If not, something is wrong with your header paths.

You can install the sqlite3 using cocopods:
pod 'sqlite3'
Or if you want the swift version:
https://github.com/stephencelis/SQLite.swift

Related

Consume FFmpeg XCFramework from Objective-C, headers not found

I built FFmpeg for Apple's platforms as an XCFramework. I used the script in https://github.com/kewlbear/FFmpeg-iOS-build-script/pull/147 to do so.
I'm trying to now consume that framework inside a traditional iOS/macOS framework (named VideoEditing), that then is used inside my iOS app (soon to try and be Catalyst).
In VideoEditing I have linked to FFmpeg.xcframework and then in the app that uses VideoEditing I have linked & embedded FFmpeg.xcframework. Previously I was building FFmpeg as a standard static library, and using that from inside VideoEditing in a Objective-C++ wrapper so I can use it all from Swift.
In that Objective-C++ file I would import FFmpeg headers like #import <libswscale/swscale.h> To make that work, I had to set header search paths. How are you supposed to do it once you convert to the XCFramework? I've tried #import FFmpeg, #import <FFmpeg/libswscale/swscale.h>, #import <FFmpeg/swscale.h> as well as #import <libswscale/swscale.h>. In every case I just get a file not found error on the import line.
All of Apple's examples are showing it just in Swift with the framework vending a module. If I was to try and still set a header search path, you now have different headers per architecture.
Try #import FFmpeg and also set Enable Modules (C and Objective C) to YES from build settings. Make sure that Link Frameworks Automatically is set to YES
You need to put header files parallel to xcframework and set header search path to that header file. xcframework is just like a single .a file, Xcode will not search headers inside xcframework.

How to use static Objective-C frameworks in a CocoaPod written in Swift?

I have a CocoaPod written in Swift 4. Now I need to add some new features to this pod. To be able to do it I need to use a static framework written in Objective-C.
I supposed I need to use a bridging header, but I don't know how should I modify my .podspec in such case. When I am trying to add a header file with this line of code:
#import <MyObjectiveCFramework/MyObjectiveCFramework.h>
to s.source_files I see this error: Include of non-modular header inside framework module.
Also, I found out that I can use a special module.modulemap file, but what data should I add to that file and how can I refer to the module.modulemap in my .podspec file?

Can Swift.h file be imported in pch file?

I'm trying to use swift in an Objective-C based project. It seems that ProjectName-Swift.h needs to be imported in every .m file which doesn't sound good. Can it be imported in the ProjectName-Prefix.pch like UIKit/UIKit.h so that I only need to type once in the project?
I've tried this way, but .pch cannot find the header file. Is there an alternative attempt?

Bridging File Not Found

The bridging file is added, but keeps showing the error.
My Bridging Header File is correctly setup because the other imports are successful.
I would advise you to use CocoaPods to handle external frameworks. Here is SlackTextViewController. If you still want to use copied version, make sure you add the files to your project. Try copying the files to your project folder using Finder and then use Xcode File -> Add files to "YOUR_PROJECT"

Xcode - how to include c library and header file to cocoa project?

How do I add c library to Xcode Cocoa project?
Or what is the best option, I don't want to copy them into Cocoa project directory.
I have a C project called a which compiles into library a.dylib and header file a.h, the project is located in it's own directory.
I want to use this library from my objective-c application in Xcode.
How do I add the header file and library to my Xcode project?
I can drag the a.dylib into other frameworks but what do I do with a.h?
I figured it out.
I point to location of project a deployment directory (headers) to Search Path in project settings either:
as Header Search Paths, if used as <a/a.h>
or into User Header Search Paths, if used as "a/a.h"
As for library I just drag it to Xcode project and set it to refer to library instead of copy.
Here are the steps before adding a header file test.h in your project. Here is the files location root -> Library -> include -> test.h
click on build settings
Find User Header Search path. add your header file location here. add following value to Debug, Release and Any Architecture field. $(SRCROOT)/Library/include. Your project Root is the folder that contains your project, it conatins .xcodeproj file.
After adding path you will be able to add header in like this
# include "test.h"
You can drag them both the .a and .h files to Xcode, but make sure to not check the "Copy items to project folder". As for referencing the header file, you'll need to put it in a place where you can add a path to it in your #include/#import statements. Is there a reason you don't want to copy the header to your project file?