lundi 13 février 2017

Referencing core data attribute from declared variable

Vote count: 0

I'm following a swift development course for beginners and am trying to make a very simple app that creates new tasks with an entered text once a button is pressed, but I am encountering a few errors that I can't seem to understand.

The errors happen in my ViewController and the editor tells me my Core Data Entity does not possess an attribute named "corename" while it very well does.

Here is a screenshot of the errors : 3 errors

And here is my code :

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")
    }
}
}

asked 1 min ago

Let's block ads! (Why?)



Referencing core data attribute from declared variable

Aucun commentaire:

Enregistrer un commentaire