0

I am really new to swift and trying to understand ios programming. Basically I have a table where "id" and "fact" columns. id is primary key'd and here is the swift fuction I am trying to query the values

func getItemsFromRow(fact_cid: String) ->[FactsData]{
    var rowData: [FactsData]!
    let rawQ = "select * from facts where \(facts_id)=?"
    if (openDatabase()){
        do{
            let results = try database.executeQuery(rawQ, value(forKey: fact_cid))
            while results.next(){
                let currentFact = FactsData(factid: results.string(forColumn: facts_id), factsdata: results.string(forColumn: facts_fld))
                if rowData == nil {
                    rowData = [FactsData]()
                }
                rowData.append(currentFact)
            }
        }
    }
    return rowData
}

But this line gives me error

let results = try database.executeQuery(rawQ, value(forKey: fact_cid))

Error is

Cannot invoke 'executeQuery' with an argument list of type '(String, Any?)'

I am trying to pass the id as string. Not sure what I am doing wrong here.

Any help is much appreciated.

1 Answer 1

1

Change it to

let results = try database.executeQuery(rawQ, values: [fact_cid])

since the second parameter should be an array

Sign up to request clarification or add additional context in comments.

3 Comments

Sorry actually now I am getting this error. Use of 'value' nearly matches class method 'value(forKey:)' in class 'NSObject' rather than instance method 'value(forKey:)'
@Achayan how, there is no “value” in my answer?
sorry I think it was mistake from my side and it is working sorry about that and thanks for the help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.