manage and persist your app's model layer
영구적으로 모델을 저장한 계층을 관리
let appdelegate = UIApplication.shared.delegate as! Appdelegate // 싱글톤으로 가져옴
appdelegate.persistentContainer.viewContext
func fetchData() {
let fetchRequest: NSFetchRequest<TodoList> = TodoList.fetchRequest()
let context = appdelegate.persistentContainer.viewContext
do {
self.todoList = try context.fetch(fetchRequest)
} catch {
print(error)
}
}
//table view
let cell = tableView.dequeReusableCell(withIdentifier: "TodoCell", for: indexPath) as! TodoCell
cell.topTitleLabel.text = todoList[indexPath.row].title
if let hasDate = todoList[indexPath.row].date {
let formatter = DateFormatter()
formatter.dateFormat = "MM-dd hh:mm:ss"
let dateString = formatter.string(from: hasDate)
cell.dateLabel.text = dateString
} else {
cell.dateLabel.text = ""
}
return cell
fetchData()
todoTableView.reloadData()