Does anyone have any idea why Xcode isn't recognizing the attributes I set for my entity?
In this block of code, the "authors" attribute works fine:
func createBook() {
let entityDescription = NSEntityDescription.entityForName("Books", inManagedObjectContext: managedObjectContext!)
let book = Books(entity: entityDescription!, insertIntoManagedObjectContext: managedObjectContext)
book.name = bookName.text
book.author = authorField.text
managedObjectContext?.save(nil)
}
Here, however, in a function in my TableViewController it says that "book" does not have an attribute "authors":
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! UITableViewCell
let book: AnyObject = newBookViewController.fetchedResultsController.objectAtIndexPath(indexPath)
cell.textLabel?.text = book.name
cell.detailTextLabel?.text = book.author
return cell
Furthermore, when I add more attributes to my Books entity in the entity inspector, even the first function does not recognize them. Also, is this the proper way to save multiple attributes at once?
func bookFetchRequest() -> NSFetchRequest {
let fetchRequest = NSFetchRequest(entityName: "Books")
let nameSortDescriptor = NSSortDescriptor(key: "name", ascending: true)
let authorSortDescriptor = NSSortDescriptor(key: "author", ascending: true)
fetchRequest.sortDescriptors = [nameSortDescriptor]
fetchRequest.sortDescriptors = [authorSortDescriptor]
return fetchRequest
}