大家好我已經嘗試了一些解決方案,但沒有運氣。可選的文本視圖顯示何時打印
我從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)")
}
}
嗨,感謝您的幫助,第一個回覆黃色三角形,它表示:在可選項檢查中使用的'String'類型的Nom-optional表達式。第二個我得到了!錯誤的=結果,說不能賦值的任何一個字符串,我試圖添加爲!字符串結尾,第三個如何得到與上面相同的錯誤,但這次我添加了!字符串在結果工作結束,謝謝你,我可以瞭解的不同選項。這是一個很大的幫助 –
我正在更新我的答案,它現在對你有用 –
再次感謝。 –