how to send multiple strings in a func swift ios for an external class

1

Very good day. I am trying to insert in sqlite with swift by means of a func: nevertheless I get this error: "Value of Type 'DataBaseHandler' has no member 'insert data2'" What would be the error?

NOTE: I have already connected the classes eg: let number_rows = DataBaseHandler (). num_row_regs ()        status.text = String (number_rows) and fuenciona correctly

    let junta = DataBaseHandler().insertar_datos2(add1: "hola", add2: "hola", add3:"hola")

print(junta)

And in DataBaseHandler:

func insertar_datos2(f1: String, f2: String, f3: String) -> String {

    databasePath = (NSTemporaryDirectory() as NSString).stringByAppendingPathComponent("dires.db")

                let contactDB = FMDatabase(path: databasePath as String)

                if contactDB.open() {

    let insertSQL = "INSERT INTO CONTACTS (name, address, phone) VALUES ('\(f1)', '\(f2)', '\(f3)')"

    let result_insert = contactDB.executeUpdate(insertSQL,withArgumentsInArray: nil)

    if !result_insert {


         self.sucess = "Fallo Al Insertar Registro."
         print("Error: \(contactDB.lastErrorMessage())")

                    } else {

                        self.sucess = "Listo. Insertado con Èxito"


                    }
                } else {
                    print("Error: \(contactDB.lastErrorMessage())")
                }


             return self.sucess

            }

        }
    
asked by GoIn Su 07.06.2016 в 23:24
source

1 answer

0

You are not calling the method correctly. The correct form would be:

let junta = DataBaseHandler().insertar_datos2("hola", f2: "hola", f3: "hola")

Also, you should not call a function directly when initializing it. That is, the previous line would be more correct in the following way:

let database = DataBaseHandler()
let junta = database.insertar_datos2("hola", f2: "hola", f3: "hola")

Finally, if your manager class does not save any status, I recommend using class methods for it. For example:

class DataBaseHandler {

    class func insertar_datos2(f1: String, f2: String, f3: String) -> String {

        //....

    }

}

So, now, you can use the method directly:

let junta = DataBaseHandler.insertar_datos2("hola", f2: "hola", f3: "hola")
    
answered by 07.06.2016 / 23:41
source