Hello:
I have a function which when called, populates the labels and textView with data from a CoreData Fetch Request, for the user. Each time the function is called I want ONLY the new data in the UI controls. Presently, the new data is appended to the old which is totally unacceptable.
How can I clear the old data so that the User sees ONLY the new data?
Thanks for helping me with the solution.
OK.
But I don't understand what you are doing here.
You loop over several items. What do they contain ?
You set questionText?.string on each loop, but only the last value will be kept
What is questionItem. A String visibly ?
You don't use stringvalue anywhere: why do you define it ?
for item in items {
questionText?.string = ""
if let record = item.value(forKey: "question") as? String {
questionItem.append(record)
let stringvalue = "questionText: \(questionItem)"
questionText?.string = questionItem
}
}
So, probably you want something closer to this:
questionText?.string = "" // in fact, not needed, just to make it easier to understand
questionItem = ""
for item in items {
if let record = item.value(forKey: "question") as? String {
questionItem.append(record)
}
}
let stringvalue = "questionText: \(questionItem)" // What is it used for ?
questionText?.string = questionItem // Or may be stringvalue ?????
Are you looping through items just to get the "question" key ?
If so, code could be:
questionItem = ""
for item in items {
if let record = item.value(forKey: "question") as? String {
questionItem = record
break // We have found the item containing question, let's leave the loop
}
}
let stringvalue = "questionText: \(questionItem)" // What is it used for ?
questionText?.string = questionItem // Or may be stringvalue ?????