大家好,我尝试了一些解决方案,但没有运气。
我从 Data Core 获取文本,但 textview 上有可选的。
当它打印时,它在文本中显示为可选。
page22TextView?.text = ("\(trans.value(forKey: "page22"))")
任何人都可以阐明这一点!试图解开,但它仍然:显示。
完整功能如下:
func getTranscriptions () {
//create a fetch request, telling it about the entity
let fetchRequest: NSFetchRequest<TextInputs> = TextInputs.fetchRequest()
do {
//go get the results
let searchResults = try getContext().fetch(fetchRequest)
//I like to check the size of the returned results!
print ("num of results = \(searchResults.count)")
//You need to convert to NSManagedObject to use 'for' loops
for trans in searchResults as [NSManagedObject] {
page22TextView?.text = ("\(trans.value(forKey: "page22"))")
//get the Key Value pairs (although there may be a better way to do that...
print("\(trans.value(forKey: "page22"))")
}
} catch {
print("Error with request: \(error)")
}
}