本文主要给大家介绍了关于在Swift 3中使用FMDB遇到的问题与解决方法,分享出来供大家参考学习,下面来一起看看详细的介绍:
[b]状况[/b]
OC项目转Swift,打算继续使用FMDB。Cocoapods进来后,在桥接文件 "XXX-Bridging-Header.h" 中写入#import "FMDB.h"。
编译报错,如下图所示。
[img]http://files.jb51.net/file_images/article/201707/2017717113906717.png?2017617113914[/img]
[img]http://files.jb51.net/file_images/article/201707/2017717113929096.png?2017617113935[/img]
Cocoapods Podfile
platform :ios, '10.0'
use_frameworks!
targetsArray = ['HelloSwift']
targetsArray.each do |t|
target t do
pod 'FMDB/SQLCipher'
pod 'Alamofire'
end
end
inhibit_all_warnings!
[b]原因[/b]
究其原因,发现是因为在Podfile用了use_frameworks!导致的。之前OC的项目没有加这个属性。
在Cocoapods 里使用use_frameworks!的话,是通过frameworks这个方式来管理pod的代码。不配置的话,则采用static libraries方式来管理。这也是之前OC项目里的方式,在需要调用的地方直接 #import "FMDB.h"即可。
[b]解决方法[/b]
在桥接文件 "XXX-Bridging-Header.h" 中的引用方式改变成[code]#import <FMDB/FMDB.h>[/code]
在需要调用的类里加上[code]import FMDB[/code],编译成功。
[img]http://files.jb51.net/file_images/article/201707/2017717114015629.png?2017617114022[/img]
示例代码
之前Cocoapods用static libraries方式的话是不需要在类里import FMDB的。但如果采用use_frameworks!属性的话,调用时不引用会报如下错误。
[img]http://files.jb51.net/file_images/article/201707/2017717114046545.png?2017617114115[/img]
参考资料
[url=http://blog.csdn.net/remote_roamer/article/details/47835347]在xcode 6.4 中使用swift和object-c混合编程,同时通过cocoapods进行管理的一些问题和解决办法](http://blog.csdn.net/remote_roamer/article/details/47835347)[/url]
[url=http://www.jianshu.com/p/8269e4cac48f]cocoapods use_frameworks的问题[/url]
[url=https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html#//apple_ref/doc/uid/TP40014216-CH10-XID_75]Swift and Objective-C in the Same Project[/url]
[b]总结[/b]
以上就是这篇文章的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对编程素材网的支持。