DimonDeveloper
DimonDeveloper

Reputation: 137

Error when save data in CoreData

I'm trying to save the data in CoreData and have got an error.

NSInvalidArgumentException', reason: '+entityForName: nil is not a legal NSManagedObjectContext parameter searching for entity name 'File''

Here is code:

-(NSMutableArray *)listFileAtPath:(NSString *)path
{
    NSMutableArray *directoryContent = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:NULL];
    return directoryContent;
}
-(void)FileData
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    File *myMO = (File*) [NSEntityDescription insertNewObjectForEntityForName:@"File" inManagedObjectContext:[self managedObjectContext]];
    [myMO setValue:[self listFileAtPath:documentsDirectory] forKey:@"filename"];
}

Why did not he see my entity?

Upvotes: 0

Views: 88

Answers (1)

Chris Wagner
Chris Wagner

Reputation: 21013

[self managedObjectContext] is returning nil according to the error message, look into this method to verify it is returning a proper NSMangedObjectContext

Upvotes: 1

Related Questions