I am new to Swift coding. Since my application will use extensively Forms, Tables and Database I am using a turorial from techtopia.com to help me get started -- "An Example SQLite based iOS 10 Application using Swift and FMDB" --
https://www.techtopia.com/index.php/An_Example_SQLite_based_iOS_8_ Application_using_Swift_and_FMDB
The problem is that after I followed all the instructions I am still getting errors. Can anyone help to know what I need to do in the ViewController.swift file to address the errors?
The Errors are below:
let contactDB = FMDatabase (path: databasePath as String) -- Use of unresolved identifier 'FMDatabase'
@IBAction func saveData(_ sender: AnyObject) { -- Only instance methods can be declared @IBAction
let contactDB = FMDatabase(path: databasePath as String) -- Use of unresolved identifier 'FMDatabase'; Use of unresolved identifier 'databasePath'
let insertSQL = "INSERT INTO CONTACTS (name, address, phone) VALUES ('\(name.text!)', '\(address.text!)', '\(phone.text!)')" --
Use of unresolved identifier 'address' ; Use of unresolved identifier 'name' ; Use of unresolved identifier 'phone'
if !result! {
status.text = "Failed to add contact"
print("Error: \(contactDB?.lastErrorMessage())")
} else {
status.text = "Contact Added" -- use of unresolved identifier 'status'
name.text = "" -- use of unresolved identifier 'name'
address.text = "" -- use of unresolved identifier 'address'
phone.text = "" -- use of unresolved identifier 'phone'
The same errors show up where ever the above code is used.
I am using an iMAC Mojave v. 10.14.3 with Xcode version 10.1 and Swift 5
[For those following along at home, this is a correct link to the tutorial.]
Use of unresolved identifier 'FMDatabase'
To fix this you’ll need to import the code that includes the
FMDatabase type. Reading through that tutorial it suggests using the bridging header approach. Did you follow those steps?
Only instance methods can be declared @IBAction
It’s hard to answer this without more context, but it seems that you’re trying to declare your action method is a standalone function rather than as a method. The declaration needs to be inside your view controller type. For example:
class ViewController … {
… stuff …
@IBAction func saveData(_ sender: AnyObject) {
… more stuff …
}
… even more stuff …
}Use of unresolved identifier 'address' ; Use of unresolved identifier 'name' ; Use of unresolved identifier 'phone'
I need more context to give you a meaningful answer. Try fixing the above two issues and let us know how you got along.
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"