Saturday, 14 September 2013

[NSURL initFileURLWithPath:]: nil string parameter'

[NSURL initFileURLWithPath:]: nil string parameter'

I want to pre populate coredata by following "this" tutorial but I had
this error "[NSURL initFileURLWithPath:]: nil string parameter" but I am
struggled to find where's the error from. I believe the error only occur
when I try to implement the core data.
I had Words.xcdatamodeld (With an entity"Words") and Words.h/m
#import "Words.h"
@implementation Words
@dynamic eng;
@dynamic kor;
@dynamic img;
@dynamic definition;
@dynamic mnemonic;
@dynamic exampleKor;
@dynamic exampleEng;
@dynamic audio;
@dynamic pronun;
@end
AppDelegate:
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
NSManagedObjectContext *context = [self managedObjectContext];
Words *word = [NSEntityDescription
insertNewObjectForEntityForName:@"Words"
inManagedObjectContext:context];
word.eng = @"ExampleWord";
word.kor = @"ExampleWord";
word.definition = @"ExampleWord";
word.mnemonic = @"ExampleWord";
word.img = @"ExampleWord";
word.pronun = @"ExampleWord";
word.exampleKor = @"ExampleWord";
word.exampleEng = @"ExampleWord";
word.audio = @"ExampleWord";
NSError *error;
if (![context save:&error]) {
NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]);
}
// Test listing all FailedBankInfos from the store
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Words"
inManagedObjectContext:context];
[fetchRequest setEntity:entity];
NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest
error:&error];
for (Words *info in fetchedObjects) {
NSLog(@"Kor: %@", info.kor);
NSLog(@"Eng: %@", info.eng);
}
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen]
bounds]];
self.viewController = [[ViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc]
initWithRootViewController: self.viewController];
self.viewController.title = @"Categories";
self.window.rootViewController = navController;
[self.window makeKeyAndVisible];
}
ViewConroller
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription
entityForName:@"Words"
inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];
NSError *error;
self.wordsArray = [managedObjectContext executeFetchRequest:fetchRequest
error:&error];
self.title = @"Words 1";

No comments:

Post a Comment