Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 775745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:20:23+00:00 2026-05-14T19:20:23+00:00

I have no trouble to create the object, but updating it fails. Here is

  • 0

I have no trouble to create the object, but updating it fails.
Here is the creation code:

 // Save data from pList to core data fro the first time
- (void) saveToCoreData:(NSDictionary *)plistDictionary {

// Create system parameter entity   
SystemParameters *systemParametersEntity = (SystemParameters *)[NSEntityDescription
                                                                insertNewObjectForEntityForName:@"SystemParameters" 
                                                                inManagedObjectContext:mManagedObjectContext];

////
// GPS SIMULATOR
////
NSDictionary *GpsSimulator = [plistDictionary valueForKey:@"GpsSimulator"];

[systemParametersEntity setMGpsSimulatorEnabled:[[GpsSimulator objectForKey:@"Enabled"] boolValue]];
[systemParametersEntity setMGpsSimulatorFileName:[GpsSimulator valueForKey:@"FileName"]];
[systemParametersEntity setMGpsSimulatorPlaybackSpeed:[[GpsSimulator objectForKey:@"PlaybackSpeed"] intValue]];

[self saveAction];  
}

During execution the cached copy is changed and then it is saved (or trying) to the database. Here is the code to save the changed copy:

// Save data from pList to core data fro the first time
- (void) saveSystemParametersToCoreData:(SystemParameters *)theSystemParameters {

// Step 1: Select Data
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];

NSEntityDescription *entity = [NSEntityDescription entityForName:@"SystemParameters" 
                                          inManagedObjectContext:mManagedObjectContext];
[fetchRequest setEntity:entity];

NSError *error = nil;
NSArray *items = [self.managedObjectContext
                  executeFetchRequest:fetchRequest error:&error];
[fetchRequest release];

if (error) {
    NSLog(@"CoreData: saveSystemParametersToCoreData: Unresolved error %@, %@", error, [error userInfo]);
    abort();
}

// Step 2: Update Object
SystemParameters *systemParameters = [items objectAtIndex:0];

////
// GPS SIMULATOR
////
[systemParameters setMGpsSimulatorEnabled:[theSystemParameters mGpsSimulatorEnabled]];
[systemParameters setMGpsSimulatorFileName:[theSystemParameters mGpsSimulatorFileName]];
[systemParameters setMGpsSimulatorPlaybackSpeed:[theSystemParameters mGpsSimulatorPlaybackSpeed]];



// Step 3: Save Updates
[self saveAction];
}

As to can see, I fetch the object that I want to update, change its values and save.
Here is the saving code:

- (void)saveAction {

NSError *error;
if (![[self mManagedObjectContext] save:&error]) {
    NSLog(@"ERROR:saveAction. Unresolved Core Data Save error %@, %@", error, [error userInfo]);
    exit(-1);
}
}

The Persistent store method:

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {

if (mPersistentStoreCoordinator != nil) {
    return mPersistentStoreCoordinator;
}

NSString    *path = [self databasePath];
NSURL *storeUrl = [NSURL fileURLWithPath:path];

NSError *error = nil;
mPersistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
if (![mPersistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:nil error:&error]) {
    NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
    abort();
}

return mPersistentStoreCoordinator;
}

The managed object class definition:

#import <Foundation/Foundation.h>


typedef enum {
UISwitchParameterIdGpsSimulatorEnable,
UISwitchParameterIdIllegal

}UISwitchParameterId;


@interface SystemParameters : NSManagedObject {

//  NSManagedObjectContext  *mManagedObjectContext;

////
// GPS SIMULATOR
////
BOOL mGpsSimulatorEnabled;
NSString *mGpsSimulatorFileName;
NSInteger mGpsSimulatorPlaybackSpeed;


}

@property (nonatomic, assign) BOOL mGpsSimulatorEnabled;
@property (nonatomic, retain) NSString *mGpsSimulatorFileName;
@property (nonatomic, assign) NSInteger mGpsSimulatorPlaybackSpeed;

+ (SystemParameters *)sharedInstance;
- (void) saveToCoreData;


@end

There is no error but the sqLite file is not updated, hence the data is not persistent.

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T19:20:23+00:00Added an answer on May 14, 2026 at 7:20 pm

    I had a very similar problem a few months back. I couldn’t get my sql store to update when running on the simulator.

    Turned out, I was looking in the wrong application folder for the simulator. If you restart the simulator or the CPU it sometimes creates an entirely new directory for the app. I kept looking at the original application folder when all the changes I had made where being written to the new one.

    If that’s not the problem, I would look at the definition of the SystemParameters class and see if there could be a fault there. A bad custom accessor or faulty validation code can cause objects not to save data without generating an error.

    Edit

    You SystemParameters class is very odd. I don’t think it will work.

    First of all, you seem to have it defined as a singleton. Core Data doesn’t recognize singletons for its entities. I’m not sure how that will work out if it will work at all.

    Second, your property definitions for you scalars are incorrect. Core Data only stores objects so BOOL attributes and integer attributes have to converted to NSNumber instances. Your properties should look like:

    @property (nonatomic, retain) NSNumber *mGpsSimulatorEnabled;
    @property (nonatomic, retain) NSString *mGpsSimulatorFileName;
    @property (nonatomic, retain) NSNumber *mGpsSimulatorPlaybackSpeed;
    

    I recommend that you let Xcode generate the managed object subclasses for you based on the entity graph. That way, you’ll get the right types and the correct handling automatically.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have trouble with calling method from another class this is my code this
Well i have some trouble removing an object from the game, the thing is
I'm having trouble obtaining data with a macro I've created using XSLT. I have
I'm having some trouble creating an object in C++. I create a class called
I've been using the following to create an array from a plist of dictionaries:
i going to create some validation for custom object in my app. But i
I have trouble connecting microstrategy to hive. I have followed every instruction here I
Extending from this question I am having trouble to understand this code. struct foo
I have trouble writing a django data model which can link multiple objects of
I'm having trouble with my code. I'm trying to create a subclass which inherits

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.