2017-02-14 6 views
0

初心者のための迅速な開発コースに従っており、ボタンを押すと入力したテキストで新しいタスクを作成する非常に簡単なアプリケーションを作成しようとしていますが、私は理解できないようです。宣言された変数からコアデータ属性を参照する

私の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") 
    } 
} 
} 
+0

コアデータに値を保存してフェッチする方法を学習してください。数多くの素晴らしいチュートリアルがあります。 –

+0

コアデータは[NSManagedObjects]型の配列を持つ必要があります。 –

+0

これで詳しい情報を調べるつもりです。インストラクターもSwift 3とXCode 9を使っているので、私はまだかなり好奇心が強いです。 –

答えて

1

タスクTaskentitiesの配列である、あなたはおそらく

をtasks.corename task.corenameにないアクセスするためのもの
if (task.isImportant == true){ 
    cell.textLabel?.text = " \(task.corename!)" 

} else { 
    cell.textLabel?.text = task.corename! 
} 

そしてTableViewDelegate問題について、ちょうどすべての必要なのfuncsを実装するようにしてください...あなたは1が欠落しています

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    return 0 
} 
+0

良い見解ですが、私はまだそれを知っていません。私は彼のコアデータ保存機能を見ることができません –

+0

彼はおそらく別のクラスからそれを保存しています。しかし、これは間違いなく彼がコンパイル時のエラーを表示している理由です(スクリーンショット)@TusharSharma – toiavalle

+1

可能かもしれません。私はすぐに緑色にマークしてください。 –

関連する問題