我如何在此数组中附加结果,以便以后使用它?
var animalQuestion = [(orderlist: Int, questionid:String, question: String, description: String)]()
这是我在上面的班级中声明的数组。
let stmt = try db.prepare("SELECT * FROM allquestion_other where allquestion_other.name= 'animalChoice' and allquestion_other.id NOT IN (select answerresult.questionId FROM answerresult where answerresult.friendUserId='(friendUserId)')")
for row in stmt {
let orderlist = row[4]
let questionid = row[0]
let question = row[6]
let description = row[7]
animalQuestion.append(orderlist: orderlist, questionid: questionid, question: question, description: description)
}
当我运行此代码时,我会收到错误"无法调用非功能类型的值'[(orderList:int,QuestionId:string,Question:string:string:string,description:string:string)]'"
行[4]行[0]行[6]行[7]正在返回一些我需要在数组中附加的值
尝试使用:
animalQuestion.append((orderlist: orderlist, questionid: questionid, question: question, description: description))
,不要忘记:
let orderlist = row[4] as Int
由于:
,您的代码不正确1)要将新对象附加到数组,您必须使用Array-Method
animalQuestion.append(<Array object>)
2)在您的情况下,数组对象是元组。因此,首先您需要创建一个元组,例如:
let orderTuple = (orderlist, questionid, question, description)
之后,在那个易于订购的订单到动物Question阵列如下:
animalQuestion.append(orderTuple)