import sqlite3.h错误:在框架模块中包含非模块化头 [英] import sqlite3.h error: include of non-modular header inside framework module
问题描述
我为我的应用程序创建了一个自定义后端框架,其中封装了所有与数据库相关的逻辑,因此,当我们要使用任何数据库操作时,我们只需要调用该框架函数。
现在,对于数据库操作,我需要在名为Data.swift的文件中的 #import
存在。但是这是swift文件,那么如何导入sqlite ..?
当我使用bridging-header.h时,我收到错误
错误:不支持使用桥接头与框架目标
$ b b
bridging-header.h中有 #import< sqlite3.h>
,并设置了Bridging Header变量。
如果我在Umbrella标头中添加import语句,这会给我错误
在框架中包含非模块化头模块
我google了很多,但无法找到正确的答案。我还查看了 https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html#//apple_ref/doc/uid/TP40014216-CH10-XID_82 并遵循
div>
据我所知你不能在一个框架中直接将Objective-C文件导入到Swift中。但是你可以在同一个框架中的另一个Objective-C类中。因此,如果你在你的框架中编写一个Objective-C类,你将能够将头文件直接包含到你的类中并使用它。
为了同样的目的,我结束了在Objective-C中为 sqlite.h
编写一个包装类,然后在我的Swift代码中访问它。
我写的是这样:
#ifndef SqlWrapper_h
#define SqlWrapper_h
struct sqlite3;
BOOL OpenDatabaseWithFileName(NSString * databaseFileName,struct sqlite3 ** database);
BOOL PrepareStatement(struct sqlite3 * database,NSString * selectStatement,struct sqlite3_stmt ** preparedStatement);
BOOL StepStatement(struct sqlite3_stmt * compiledStatement);
BOOL FinalizeStatement(struct sqlite3_stmt * compiledStatement);
NSInteger NumberOfRowsAffected(struct sqlite3 * database);
NSInteger LastInsertedRowID(struct sqlite3 * database);
NSInteger GetColumnCount(struct sqlite3_stmt * compiledStatement);
const unsigned char * GetColumnValue(struct sqlite3_stmt * compiledStatement,int index);
NSInteger GetColumnValueInInteger(struct sqlite3_stmt * compiledStatement,int index);
double GetColumnValueInDouble(struct sqlite3_stmt * compiledStatement,int index);
BOOL CloseDatabase(struct sqlite3 * database);
#endif
每个函数都包含sqlite3方法。这些可以在同一个框架中从你的Swift类中调用。
I am creating a custom back-end framework for my app which encapsulates all my database related logic, so, when we are going to use any database operation, we just need to call that framework function.
Now, for database operations I need to #import <sqlite3.h>
in the file called Data.swift where my all database functions exist. But this is swift file so how can I import sqlite..?
When I use bridging-header.h, I receive error
error: using bridging headers with framework targets is unsupported
bridging-header.h has #import <sqlite3.h>
inside it and set settings Bridging Header variable.
If I add import statement in Umbrella header which gives me the error
include of non-modular header inside framework module
I googled a lot but unable to find proper answer. I also looked upon https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html#//apple_ref/doc/uid/TP40014216-CH10-XID_82 and followed it properly but I think I still miss something.
Please suggest me something.
As far as I know you can not directly import Objective-C files into Swift in a framework. But you could do it in another Objective-C classes in he same framework. So if you write an Objective-C class in your framework you will be able to include the header file directly into your class and use it.
For the same purpose I ended up writing a wrapper class for sqlite.h
in Objective-C and then access that in my Swift code. The header for wrapper class you write must be made public and added to your umbrella header.
I wrote something like this:
#ifndef SqlWrapper_h
#define SqlWrapper_h
struct sqlite3;
BOOL OpenDatabaseWithFileName(NSString* databaseFileName, struct sqlite3** database);
BOOL PrepareStatement(struct sqlite3* database,NSString *selectStatement,struct sqlite3_stmt** preparedStatement);
BOOL StepStatement(struct sqlite3_stmt* compiledStatement);
BOOL FinalizeStatement(struct sqlite3_stmt* compiledStatement);
NSInteger NumberOfRowsAffected(struct sqlite3* database);
NSInteger LastInsertedRowID(struct sqlite3* database);
NSInteger GetColumnCount(struct sqlite3_stmt* compiledStatement);
const unsigned char* GetColumnValue(struct sqlite3_stmt* compiledStatement,int index);
NSInteger GetColumnValueInInteger(struct sqlite3_stmt* compiledStatement,int index);
double GetColumnValueInDouble(struct sqlite3_stmt* compiledStatement,int index);
BOOL CloseDatabase(struct sqlite3* database);
#endif
Each of these function wraps sqlite3 methods. These could be called from your Swift classes in the same framework.
这篇关于import sqlite3.h错误:在框架模块中包含非模块化头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!