模糊地使用' numberOfPages'

时间:2015-08-01 20:32:51

标签: ios swift xcode6

我不明白我在TableViewController中使用book.numberOfPages有什么含糊之处。我使用任何其他属性都没有任何问题。这里不应该有任何歧义:我在数据模型编辑器和TableViewController的顶部将它定义为Float。

 override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
            if segue.identifier == "showBookDetail" {
                let indexPath:NSIndexPath = self.tableView.indexPathForSelectedRow()!
                let book: AnyObject = addBookViewController.fetchedResultsController.objectAtIndexPath(indexPath) as! Book
                var detailViewController:BookDetailViewController = segue.destinationViewController as! BookDetailViewController
                detailViewController.title = book.name
                detailViewController.pagesReadText = "\(Int(book.pagesRead))"
                detailViewController.timeReadText = "\(Int(book.timeRead))"
                println(book.numberOfPages)
            }
        }

1 个答案:

答案 0 :(得分:1)

可能你不能将book声明为AnyObject,因此编译器知道它是Book ...

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
            if segue.identifier == "showBookDetail" {
                let indexPath:NSIndexPath = self.tableView.indexPathForSelectedRow()!
                let book = addBookViewController.fetchedResultsController.objectAtIndexPath(indexPath) as! Book
                var detailViewController:BookDetailViewController = segue.destinationViewController as! BookDetailViewController
                detailViewController.title = book.name
                detailViewController.pagesReadText = "\(Int(book.pagesRead))"
                detailViewController.timeReadText = "\(Int(book.timeRead))"
                println(book.numberOfPages)
            }
        }