解析这个 crash的原因。
唉,不得不猜测一下:headfirst写这本书写的太着急了,以至于sample code都有问题。
有问题没关系我们研究解决。
'+entityForName: could not locate an NSManagedObjectModel for entity name 'Fugitive''
这个是其中出现crash 时的log.
单步跟踪 如下代码:
iBountyHunterAppDelegate *appDelegate = (iBountyHunterAppDelegate*)[[UIApplicationsharedApplication]delegate];
NSManagedObjectContext *managedObjectContext = appDelegate.managedObjectContext;
发现了一个严重问题 appDelegate = nil。 原来是这个道理,所以导致 managedObjectContext始终为nil。
说明iBountyHunterAppDelegate中的代码没有运行。
那么是什么原因呢?
打开 mainWindow.xib 会发现 黄色立方体 app delegate中的 Referencing Outlets 是空的。
将这个选中 拖到 file's owner上就可以解决这个问题了。