Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have some suggestions, too big for a comment. </p> <p>1) after you create the WeaponsRanged, try reading them back:</p> <pre><code>for(NSDictionary *item in jsonWeaponRanged) { WeaponsRanged *wr = [NSEntityDescription insertNewObjectForEntityForName:@"WeaponsRanged" inManagedObjectContext:context]; NSLog(@"IS WR Realized? %@", wr ? @"YES" : @"NOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO WR"); ///***/// wr.recoil = [item objectForKey:@"Recoil"]; ///***/// NSError *error; if(![context save:&amp;error]) NSLog(@"%@", [error localizedDescription]); } // Now lets see if we can retrieve them: { NSEntityDescription *entiRange = [NSEntityDescription entityForName:@"WeaponsRanged" inManagedObjectContext:context]; NSFetchRequest *frRanged = [[NSFetchRequest alloc] init]; [frRanged setEntity:entiRange]; NSError *errorRanged = nil; arrRange = [context executeFetchRequest:frRanged error:&amp;errorRanged]; NSLog(@"Wrote %i items, read back %i items", [jsonWeaponRanged count], [arrRange count] ); } </code></pre> <p>2) In the viewController reading WeaponsRanged, add an assert before the fetch on mod:</p> <pre><code> NSLog(@"IS moc set? %@", moc ? @"YES" : @"NOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO MOC"); </code></pre> <p>EDIT: </p> <p>3) Spread statements everywhere you access the MOC:</p> <pre><code>assert([NSThread isMainThread]); </code></pre> <p>[If you haven't used asserts before google and read up on the topic. These are a powerful tool for developers to find out about potential problems way before they manifest themselves in the gui or elsewhere. They are normally compiled out for release/distribution builds.]</p> <p>This will force an exception if the thread is not the main thread, and then let you track down the reason by following the stack trace.</p>
    singulars
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. COI can assure you that the data gets saved properly, as I can preview the .sqlite file and see the data. BUT, now I can't reproduce the problem on the simulator. When I launch the simulator, it shows everything. When I launch it on the device, it has the same problem as before. It is completely random, earlier it was the other way around. I have no idea what's causing this.. The assert did not work.. (I don't really know what it does, but it didn't fix this..)
      singulars
    2. COAsserts just say - I "assert" what is inside is true. So it didn't work - it crashed? That means moc is nil. Change the asserts to NSLogs and make sure the values inside the asserts are not nil. Also, if you don't want to try the code I gave you, since you know the sql is proper, well then, I guess you can fix it yourself. Its not just me - others are reading this. You're telling us the SQL looks great does nothing to solve the basic issue - which is Core Data apparently is now working for you. For the record its working for millions of people all over the world right now.
      singulars
    3. CONo, it didn't crash. Nothing crashes, I just don't get any information from the request. moc is set. And as you see, I always use the same moc to all three requests. Maybe that is the problem? But that doesn't explain how it works sometimes.. For me, it seems like the fetch is bugged. As if the return of a "SELECT * FROM Table" is empty. It still returns as an array, but an empty array. I can't tell why it is empty sometimes.. Right now I am unable to reproduce the problem.. And I have done nothing to fix it. Seems random. I don't want it to happen after launch..
      singulars
 

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