There is an issue that i can't understand and can not find an answer to: i have this method in a tableViewCOntroller that is calling another viewCOntroller with TableView inside it
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "ShowBook" {
if let selectedIndexPath = tableView.indexPathForSelectedRow {
let books = categoryStore.allCategories[selectedIndexPath.row].books
let destinationVC = segue.destinationViewController as! BookViewController
destinationVC.books = books
}
}
}
Then in the BookViewController i have this just for testing:
var books = [Book]()
override func viewDidLoad() {
super.viewDidLoad()
print(books[0].name)
}
I can see that the books var is an array that is holding books:
class Book {
var name: String = ""
var id: Int = -1
var categoryId: Int = -1
var bookAuthor: String = ""
var level1Name: String = ""
var level2Name: String = ""
var level3Name: String = ""
var level4Name: String = ""
var levels: Int = -1
var orderKey: Int = -1
var viewCount: Int = -1
var viewLevel: Int = -1
var chapters: [AnyObject] = []
}
so i am getting an array of books with 13 key/value pairs dictionary in the books var
when i'm trying to print any thing, lets say:
print(books[0].name)
I get the error:
fatal error: NSArray element failed to match the Swift Array Element type
and i can't understand why...
p.s The transition is working and i can see the next table but then getting the fatal error

categoryStore.allCategories[selectedIndexPath.row].bookslook like? The debugger seems to indicate that you're dealing with dictionaries rather thanBooks if I'm reading this right. Try printingbooks[0]first rather than accessing the element.NSArrayofNSDictionarys. A dictionary entry is not the same as aclassinstance with 13 properties.var books = [[NSObject: AnyObject]]()and thenprint(books[0]["name"]!).booksas an array ofBookobjects but then you have assigned an array ofNSDictionary. It looks like you need to create an initialiser forBookthat takes a dictionary and then interate your array of NSDictionaries, creating Books and putting them in an array