Swift字典包含值,但不会在调试器控制台上打印

问题描述 投票:0回答:2

我正在这样的字典中创建和打印值

let answersToSubmit = SubmitAnswerModel() //main model
let realm = try! Realm()
let savedExamResponse = realm.object(ofType: SavedExamResponse.self, forPrimaryKey: id)
answersToSubmit.uniqid = savedExamResponse?.uniqueId

var answerListToSubmit =  [QuestionAnswersToSubmit]()

for item in (savedExamResponse?.questionAnswerList)! {
    let answerToSubmit = QuestionAnswersToSubmit()
    answerToSubmit.qid =  item.questionId
    answerToSubmit.value.append(item.selectedOption)            
    answerListToSubmit.append(answerToSubmit)

}

answersToSubmit.answers = answerListToSubmit
print("length %s ",answersToSubmit.answers.count)//this is printing 100
print("answers to submit %s",answersToSubmit)//this is printing only the first part

输出是这样的

length %s  100
answers to submit %s SubmitAnswerModel {
    uniqid = test-5cb2f6a2d81034.66536499;
    //the rest of the object needs to printed here, isn't it
}

所以我不太确定如果我已经附加数组并将其放入字典中。任何帮助,将不胜感激。谢谢

ios arrays swift dictionary
2个回答
1
投票

如果您想要更全面的日志输出,请尝试使用dump()函数:

dump(answersToSubmit)

这会向控制台输出更多信息。


0
投票

这是你的for语句中的预期输出。我不确定为什么你试图追加,领域不会像这样处理数组。如果需要存储数组,则可能需要使用领域列表。

但是从您展示的代码中,这应该可行。

 for item in (savedExamResponse?.questionAnswerList)! {
   let answerToSubmit = QuestionAnswersToSubmit()
   answerToSubmit.qid =  item.questionId
   answerToSubmit.value = item.selectedOption          
   answerListToSubmit = answerToSubmit

}

© www.soinside.com 2019 - 2024. All rights reserved.