我查看了所有其他具有相同错误的帖子(使用未声明的类型),但仍然无法弄清楚我的项目有什么问题。
与其他情况的不同之处在于,我可以在 AppDelegate 和 ViewController 类中成功使用 FMDatabase,但不能从我创建的另一个类中使用,尽管与 AppDelegate 和 ViewController 类在同一个项目中。
通过“成功使用”,我的意思是我可以访问其中的数据库和表。
另请注意,我无需导入任何内容即可在 AppDelegate 或 ViewController 中使用 FMDatabase。
到目前为止我所做的(Xcode。6.4 Swift 1.2):
创建了一个单一的视图 swift 项目。
使用 cocoapods 安装 FMDB ( https://cocoapods.org/?q=fmdb )
为 FMDB 创建了一个桥接头
我可以从 AppDelegate.swift 和 ViewController.swift 类中成功声明和使用 FMDatabase。
AppDelegate.swift
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var database: FMDatabase? // OK
...
ViewController.swift
class ViewController: UIViewController {
var database: FMDatabase? // OK
...
在 DBUtil.swift 中,虽然我收到“使用未声明的类型 'FMDatabase'”错误。
DBUtil.swift
class DBUtil {
var database: FMDatabase? // Error: "Use of undeclared type 'FMDatabase'
}
Swift Bridging Header提供了一个复制器。
对于任何提示或想法,提前谢谢你。