0

私は 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
4

2 に答える 2

0

ファイルが存在するかどうかを確認しようとしましたか?

NSURL *test;
if ([[NSBundle mainBundle] pathForResource:@"Marko1" ofType:@"momd"]) {
    test = [[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Marko1" ofType:@"momd"]];
} else {
    NSLog(@"File could not be located");
}

または、次のように使用してみてください。

NSString *modelPath = [[NSBundle mainBundle] pathForResource:@"Makro1" ofType:@"momd"];
NSManagedObjectModel *objectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:[NSURL fileURLWithPath:modelPath]];
于 2013-06-10T08:12:25.230 に答える
0

この種のクラッシュを見たことがありますが、これはパスがこの行で nil を返したためです。

NSURL *modelURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Marko1" ofType:@"momd"]];

1.パスをログに記録する

 NSLog(@"%@",[[NSBundle mainBundle] pathForResource:@"Marko1" ofType:@"momd"]);

2.insted of momdtry withmom

于 2013-06-10T05:50:49.857 に答える