Note that there are some explanatory texts on larger screens.

plurals
  1. POCoreData - could not locate an NSManagedObjectModel
    primarykey
    data
    text
    <p>I'm getting the error below, I don't know what I'm doing wrong.</p> <p>I guess there is the managedobject which cannot be located, but... arf !</p> <pre><code> *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name 'Boxes'' </code></pre> <p>here is my .m ( only the two main functions )</p> <pre><code> - (void)loadCoreData { [[NSNotificationCenter defaultCenter] postNotificationName:@"Test" object:self]; context = [app managedObjectContext]; NSError *err; // GET THE JSON NSString *urlString = [NSString stringWithFormat:@"http://localhost:8888/json.txt"]; NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlString]]; NSMutableArray *json = (NSMutableArray* )[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&amp;err]; // FILL THE ENTITY for (int i = 0; i != 7; i++) { Boxes *boxes = [NSEntityDescription insertNewObjectForEntityForName:@"Boxes" inManagedObjectContext:context]; boxes.name = [[[json valueForKey:@"boxesDetail"] objectAtIndex:i] valueForKey:@"name"] ; boxes.sexe = [[[json valueForKey:@"boxesDetail"] objectAtIndex:i] valueForKey:@"sexe"] ; boxes.topic = [[[json valueForKey:@"boxesDetail"] objectAtIndex:i] valueForKey:@"topic"] ; boxes.number = [NSNumber numberWithInt:[[[[json valueForKey:@"boxesDetail"] objectAtIndex:i] valueForKey:@"number"] intValue]]; } request = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Boxes" inManagedObjectContext:context]; [request setEntity:entity]; arrayForPredicate = [context executeFetchRequest:request error:&amp;err]; } - (void) fillSexArray:(NSString *)sexe { // PREDICATE TO GET AN ARRAY OF PRODUCT WITH SEXE EQUAL TO NSPredicate *sex; if ([sexe isEqualToString:@"both"]) { sex = [NSPredicate predicateWithFormat:@"sexe = %@ OR sexe = %@", @"female", @"male"]; } else { sex = [NSPredicate predicateWithFormat:@"sexe = %@", sexe]; } NSArray *BoxWithSex = [arrayForPredicate filteredArrayUsingPredicate:sex]; NSMutableArray *mutableArray = [self createMutableArray:BoxWithSex]; // NSLog(@"%@", [[mutableArray objectAtIndex:1] valueForKey:@"name"]); // NSUInteger numObjects = [mutableArray count]; } </code></pre> <p>my .h :</p> <pre><code>@interface AddViewController : UIViewController </code></pre> <p>{</p> <pre><code>IBOutlet UIButton *male; IBOutlet UIButton *female; IBOutlet UIButton *couple; UIButton *maleBtn; BOOL flag; NSArray *arrayForPredicate; NSFetchedResultsController *fetchedResultsController; NSManagedObjectContext *context; NSFetchRequest *request; </code></pre> <p>}</p> <pre><code>@property (nonatomic, retain) WonderAppDelegate *app; - (void) fillSexArray:(NSString *)sexe; - (NSMutableArray *)createMutableArray:(NSArray *)array; - (void)loadCoreData; - (void)sexeButtonPressed; - (void)sexeArray; @end </code></pre> <p>EDIT creating the managedObject : </p> <pre><code>+ (id)boxWithDictionary:(NSDictionary *)dict withManagedObjectContext:(NSManagedObjectContext *)managedObjectContext; { Boxes *boxes = [NSEntityDescription insertNewObjectForEntityForName:@"Boxes" inManagedObjectContext:managedObjectContext]; boxes.name = [dict objectForKey:@"name"]; boxes.sexe = [dict objectForKey:@"sexe"]; boxes.topic = [dict objectForKey:@"topic"]; boxes.number = [dict objectForKey:@"number"]; return boxes; } </code></pre> <p>This is my .m and it is working like that but i don't want the code of the function Add there i want it on loadCoreData.</p> <pre><code>// // AddViewController.m // CoreDataTuto // // Created by Clement Yerochewski on 30/04/12. // Copyright (c) 2012 Weblib. All rights reserved. // #import "AddViewController.h" #import "Boxes.h" @implementation AddViewController @synthesize app, context; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 768, 44)]; UINavigationItem *navItem = [[UINavigationItem alloc] initWithTitle:@"Add Detail"]; [navBar pushNavigationItem:navItem animated:NO]; UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStylePlain target:self action:@selector(cancel)]; UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithTitle:@"Add" style:UIBarButtonItemStyleBordered target:self action:@selector(add)]; navItem.leftBarButtonItem = cancelButton; navItem.rightBarButtonItem = addButton; [self.view addSubview:navBar]; app = [[UIApplication sharedApplication] delegate]; } return self; } - (void) add{ [self dismissModalViewControllerAnimated:YES]; // PREDICATE TO GET AN ARRAY OF PRODUCT WITH A LENGTH NAME &lt;= 5 // NSPredicate *length; // length = [NSPredicate predicateWithFormat:@"name.length &lt;= 5"]; // NSArray *BoxWithCheapPrice = [array filteredArrayUsingPredicate:length]; // NSLog(@"Box %@", BoxWithCheapPrice); // PREDICATE TO GET AN ARRAY OF PRODUCT WITH PRICE BETWEEN $MIN AND $MAX // NSNumber *min = [NSNumber numberWithInteger:30]; // NSNumber *max = [NSNumber numberWithInteger:100]; // NSPredicate *between; // between = [NSPredicate predicateWithFormat:@"number BETWEEN %@", [NSArray arrayWithObjects:min, max, nil]]; // NSArray *BoxWithPriceBetween = [array filteredArrayUsingPredicate:between]; // NSLog(@"Box %@", BoxWithPriceBetween); // NSLog(@"%@", [BoxWithPriceBetween valueForKey:@"name"]); } - (NSMutableArray *)createMutableArray:(NSArray *)array { return [NSMutableArray arrayWithArray:array]; } - (IBAction) sexeChoosen: (id) sender { switch ( ((UIButton*)sender).tag ){ case 0: [self fillSexArray:@"male"]; break; case 1: [self fillSexArray:@"female"]; break; default: [self fillSexArray:@"both"]; } [self sexeButtonPressed]; } - (void)sexeButtonPressed { if (flag) { UIImage * maleImg2 = [UIImage imageNamed:@"pressed.png"]; [maleBtn setImage:maleImg2 forState:UIControlStateNormal]; flag = NO; [self sexeArray]; } else { UIImage * maleImg1 = [UIImage imageNamed:@"unpressed.png"]; [maleBtn setImage:maleImg1 forState:UIControlStateNormal]; flag = YES; [self sexeArray]; } } - (void)sexeArray { } - (void)loadCoreData { } - (void) fillSexArray:(NSString *)sexe { context = [app managedObjectContext]; // GET THE JSON NSString *urlString = [NSString stringWithFormat:@"http://localhost:8888/json.txt"]; NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlString]]; NSError *err; NSMutableArray *json = (NSMutableArray* )[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&amp;err]; // FILL THE ENTITY for (int i = 0; i != 7; i++) { Boxes *boxes = [NSEntityDescription insertNewObjectForEntityForName:@"Boxes" inManagedObjectContext:context]; boxes.name = [[[json valueForKey:@"boxesDetail"] objectAtIndex:i] valueForKey:@"name"] ; boxes.sexe = [[[json valueForKey:@"boxesDetail"] objectAtIndex:i] valueForKey:@"sexe"] ; boxes.topic = [[[json valueForKey:@"boxesDetail"] objectAtIndex:i] valueForKey:@"topic"] ; boxes.number = [NSNumber numberWithInt:[[[[json valueForKey:@"boxesDetail"] objectAtIndex:i] valueForKey:@"number"] intValue]]; } NSFetchRequest *request = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Boxes" inManagedObjectContext:context]; [request setEntity:entity]; arrayForPredicate = [context executeFetchRequest:request error:&amp;err]; NSPredicate *sex; // PREDICATE TO GET AN ARRAY OF PRODUCT WITH SEXE EQUAL TO if ([sexe isEqualToString:@"both"]) { sex = [NSPredicate predicateWithFormat:@"sexe = %@ OR sexe = %@", @"female", @"male"]; } else { sex = [NSPredicate predicateWithFormat:@"sexe = %@", sexe]; } NSArray *BoxWithSex = [arrayForPredicate filteredArrayUsingPredicate:sex]; NSMutableArray *mutableArray = [self createMutableArray:BoxWithSex]; NSLog(@"SEXE CHOOSEN %@", mutableArray); // NSLog(@"%@", [[mutableArray objectAtIndex:1] valueForKey:@"name"]); NSUInteger numObjects = [mutableArray count]; NSLog(@"%d", numObjects); } - (void) cancel{ [self dismissModalViewControllerAnimated:YES]; } - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Release any cached data, images, etc that aren't in use. } #pragma mark - View lifecycle - (void)viewDidLoad { flag = YES; maleBtn = [UIButton buttonWithType:UIButtonTypeCustom]; maleBtn.frame = CGRectMake(40, 47, 107, 75); [maleBtn setTitle:@"male" forState:UIControlStateNormal]; UIImage * maleImg1 = [UIImage imageNamed:@"unpressed.png"]; [maleBtn setImage:maleImg1 forState:UIControlStateNormal]; [maleBtn addTarget:self action:@selector(sexeChoosen:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:maleBtn]; [self loadCoreData]; [super viewDidLoad]; // Do any additional setup after loading the view from its nib. } - (void)viewDidUnload { [super viewDidUnload]; // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); } @end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload