初心者のための迅速な開発コースに従っており、ボタンを押すと入力したテキストで新しいタスクを作成する非常に簡単なアプリケーションを作成しようとしていますが、私は理解できないようです。宣言された変数からコアデータ属性を参照する
私のViewControllerでエラーが発生し、エディタは私のCore Data Entityが "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を使っているので、私はまだかなり好奇心が強いです。 –