【发布时间】:2018-04-02 06:21:12
【问题描述】:
是什么导致了ff中的错误。行以及如何解决 itreward: (rewardField?.text) 是说不能转换“字符串”类型的值?到预期的参数类型 'Int64' swift ios 。顺便说一句,代码 db 中奖励的实体类型是 int64 。
谢谢
self.saveDataInCoreData(nameOfGroccery: (textField?.text)! , detail: (detailField?.text)! , reward: (rewardField?.text))
func saveDataInCoreData(nameOfGroccery:String , detail: String , reward: Int64){
let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
let groceryData = GroceryItem(context: context) // Link GroceryItem & Context
groceryData.name = nameOfGroccery
groceryData.detail = detail
groceryData.reward = reward
groceryData.isSelected = false
groceryData.houseNo = loggedInUserHouseNumber
// print("data:", groceryItem.name)
(UIApplication.shared.delegate as! AppDelegate).saveContext()
}
【问题讨论】:
-
尝试像 (rewardField?.text) 一样解开rewardField.text!
-
在你的方法 saveDataInCoreData() 中,reward 的数据类型看起来是 Int64,而不是 String。
-
我试过拆开它
-
是的,正是它的 int 64
-
文本字段中的文本是字符串,即使字符串是数字。