【发布时间】:2017-02-14 03:39:04
【问题描述】:
我正在学习针对初学者的快速开发课程,并正在尝试制作一个非常简单的应用程序,该应用程序可以在按下按钮后使用输入的文本创建新任务,但是我遇到了一些我似乎无法解决的错误明白。
错误发生在我的 ViewController 中,编辑器告诉我我的核心数据实体不具有名为“corename”的属性,而它确实很好。
这里是错误截图:3 errors
这是我的代码:
import UIKit
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak var tableView: UITableView!
var tasks : [Taskentity] = []
override func viewDidLoad() {
super.viewDidLoad()
tableView.dataSource = self
tableView.delegate = self
// Do any additional setup after loading the view, typically from a nib.
}
override func viewWillAppear(_ animated: Bool) {
//Get the data from Core data
getData()
//Reload the table view
tableView.reloadData()
}
func numberOfSections(in tableView: UITableView) -> Int {
return tasks.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath : IndexPath) -> UITableViewCell {
let cell = UITableViewCell()
let task = tasks[indexPath.row]
if (task.isImportant == true){
cell.textLabel?.text = "???? \(tasks.corename!)"
} else {
cell.textLabel?.text = tasks.corename!
}
return cell
}
func getData() {
let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
do {
tasks = try context.fetch(Taskentity.fetchRequest())
} catch {
print("Fetching Data")
}
}
}
【问题讨论】:
-
请研究如何在核心数据中保存和获取价值,那里有很多很棒的教程。
-
核心数据应该有 [NSManagedObjects] 类型的数组。
-
好的,我会尝试查找更多相关信息。我仍然很好奇,因为讲师也在使用 Swift 3 和 XCode 9,并且对他有用。
-
核心数据中的数据保存在哪里?你的核心数据模型类在哪里。
-
他有Taskentity数组就可以了,只要Taskentity实现NSManagedObject @TusharSharma
标签: ios swift core-data swift3