你好,我想使用警告文本框添加姓名、日期和详细信息等数据,这是否可能?就像我想将这些“let”分配给每个文本框输入代码一样。
func addData(){
//Date Formatter
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy/MM/dd"
let name = "Abhirajsinh"
let dateAdded = Date() // In Realtime it would come from datePicker
let strDateAdded = dateFormatter.string(from: dateAdded)
let dateExpiration = Date() // In Realtime it would come from datePicker
let strDateExpiration = dateFormatter.string(from: dateExpiration)
let details = "This is demo Detail"
saveData(name: name, dateAdded: strDateAdded, dateExpiration: strDateExpiration, details: details) // USe it like this
}
func saveData(name:String,dateAdded:String,dateExpiration:String,details:String){
let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
let groceryData = GroceryItem(context: context) // Link GroceryItem & Context
groceryData.name = name
groceryData.dateAdded = dateAdded
groceryData.dateExpiration = dateExpiration
groceryData.details = details
(UIApplication.shared.delegate as! AppDelegate).saveContext()
}