我是 xcode 的新手并遵循这个 RestKit 教程: https ://github.com/RestKit/RKGist/blob/master/TUTORIAL.md 我已经成功完成了一次。我将再次检查它并对其进行自定义以满足我的需求,并且出于某种原因,很早就(甚至在我做出任何真正的偏差之前)应用程序在模拟器上崩溃了。我建立了数据模型,配置了RestKit和CoreData,然后在tut中第一次模拟失败了。这是我尝试运行它时遇到的错误:
2013-06-09 18:37:10.121 marko1[16183:c07] I restkit:RKLog.m:34 RestKit logging initialized...
2013-06-09 18:37:10.148 marko1[16183:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter'
*** First throw call stack:
(0x1b24012 0x1949e7e 0x1b23deb 0x13609b1 0x136093b 0x26db 0x88b157 0x88b747 0x88c94b 0x89dcb5 0x89ebeb 0x890698 0x25c0df9 0x25c0ad0 0x1a99bf5 0x1a99962 0x1acabb6 0x1ac9f44 0x1ac9e1b 0x88c17a 0x88dffc 0x25dd 0x2505 0x1)
libc++abi.dylib: terminate called throwing an exception
在上面,它显示了 main.m 文件中的这行代码:
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
我无法弄清楚,因为我从我创建的功能版本中克隆了代码,但它仍然崩溃。任何帮助都会很大——即使它只是抽象地解释这意味着什么以及如何解决这个问题。提前致谢!
这是我调用 NSURL 的 AppDelegate.m 文件(以及异常断点指向我的位置)。
#import "AppDelegate.h"
#import <RestKit/RestKit.h>
#import "MasterViewController.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSError *error = nil;
NSURL *modelURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Marko1" ofType:@"momd"]];
NSManagedObjectModel *managedObjectModel = [[[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL] mutableCopy];
RKManagedObjectStore *managedObjectStore = [[RKManagedObjectStore alloc] initWithManagedObjectModel:managedObjectModel];
//Initialize the Core Data Stack
[managedObjectStore createPersistentStoreCoordinator];
NSPersistentStore __unused *persistentStore = [managedObjectStore addInMemoryPersistentStore:&error];
NSAssert(persistentStore, @"Failed to add persistent store: %@", error);
[managedObjectStore createManagedObjectContexts];
//Set the default store shared instance
[RKManagedObjectStore setDefaultStore:managedObjectStore];
//Override point for customization after application launch.
UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
MasterViewController *controller = (MasterViewController *)navigationController.topViewController;
controller.managedObjectContext = managedObjectStore.mainQueueManagedObjectContext;
return YES;
}
@end