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 6639169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:31:21+00:00 2026-05-25T23:31:21+00:00

I have a fairly simple iPhone app which utilizes CoreData for object persistence. The

  • 0

I have a fairly simple iPhone app which utilizes CoreData for object persistence.
The object has, amongst other attributes, an NSNumber attribute, defined in the datamodel along with all the other attributes. I set this during the application run cycle to 1 if the user clicks on a particular button. I then call the store function which definitely does get called, and is the same function as persisted everything else, and this seems to work temporarily, in that if I check the value of the attribute on my NSManagedObject it has the correct value, if I retrieve the object from the data store and check it it still has the right value. However if I restart the app, it has not persisted, and so it reverts to the default. I’m getting quite frustrated and have tried various methods of forcing the ManagedObjectContext to persist.

Relevant code:
Persistence code…

- (Area*) storeAreaFavourite:(Area*)a
{
    a = [self storeArea:a];
    NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];
        //[context refreshObject:a mergeChanges:YES];
    [context processPendingChanges];
    NSLog(@"Stored area with favourite: %@",([a favourite] != nil ? [a favourite] : [NSNumber numberWithInt: 0]));
    return a;
}

- (Area*) storeArea:(Area*)a
{
    NSError *error = nil;
        // Create a new instance of the entity managed by the fetched results controller.
    NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];
    NSFetchRequest* request = [[NSFetchRequest alloc] init];
    NSEntityDescription* entity = [NSEntityDescription entityForName:@"Area" inManagedObjectContext:context];
    NSPredicate* predicate = [NSPredicate predicateWithFormat:@"areaId=%@", [a areaId]];
    [request setEntity:entity];
    [request setPredicate:predicate];
    NSArray* matchedAreas = [context executeFetchRequest:request error:&error];
    if (error != nil)
    {
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
    }
        //NSLog(@"Matched %d Areas", [matchedAreas count]);
    Area* newArea = [matchedAreas count] > 0 ? [matchedAreas objectAtIndex:0] : nil;
    if (newArea == nil)
    {
        newArea = [NSEntityDescription insertNewObjectForEntityForName:@"Area" inManagedObjectContext:context];
    }
    else {
            //NSLog(@"Area: %@ -> %@ ParentArea: %@ -> %@", [newArea valueForKey:@"areaId"], [a areaId], [(Area*)[newArea  valueForKey:@"parentArea"] areaId], [(Area*)[a parentArea] areaId]);
    }


        // If appropriate, configure the new managed object.
    [newArea setValue:[a areaId] forKey:@"areaId"];
    [newArea setValue:[a areaName] forKey:@"areaName"];
    [newArea setValue:[a parentArea] forKey:@"parentArea"];
    [newArea setValue:[a height] forKey:@"height"];
    [newArea setValue:[a width] forKey:@"width"];
    [newArea setValue:[a xPos] forKey:@"xPos"];
    [newArea setValue:[a yPos] forKey:@"yPos"];
    [newArea setValue:[a childAreas] forKey:@"childAreas"];
    [newArea setValue:[a imageName] forKey:@"imageName"];
    [newArea setValue:[a areaText] forKey:@"areaText"];
    [newArea setValue:([a favourite] != nil ? [a favourite] : [NSNumber numberWithInt: 0]) forKey:@"favourite"];
    if ([a favourite] != nil && [[NSNumber numberWithInt:1] isEqualToNumber:[a favourite]])
    {
        NSLog(@"Storing area with areaId: %@",[a areaId]);
        NSLog(@"Storing area with areaName: %@",[a areaName]);
        NSLog(@"Storing area with parentArea: %@",[a parentArea]);
        NSLog(@"Storing area with height: %@",[a height]);
        NSLog(@"Storing area with width: %@",[a width]);
        NSLog(@"Storing area with xPos: %@",[a xPos]);
        NSLog(@"Storing area with yPos: %@",[a yPos]);
        NSLog(@"Storing area with childAreas: %@",[a childAreas]);        
        NSLog(@"Storing area with imageName: %@",[a imageName]);
        NSLog(@"Storing area with areaText: %@",[a areaText]);
        NSLog(@"Storing area with favourite: %@",([a favourite] != nil ? [a favourite] : [NSNumber numberWithInt: 0]));
    }

        // Save the context.
    if (![context save:&error]) {
        /*
         Replace this implementation with code to handle the error appropriately.

         abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. If it is not possible to recover from the error, display an alert panel that instructs the user to quit the application by pressing the Home button.
         */
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
            //abort();
    }

    matchedAreas = [context executeFetchRequest:request error:&error];
    if (error != nil)
    {
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
    }
        //NSLog(@"Matched %d Areas", [matchedAreas count]);
    newArea = [matchedAreas count] > 0 ? [matchedAreas objectAtIndex:0] : nil;
    if (newArea != nil)
    {
        NSLog(@"StoredFav:%@:%@",[newArea areaId],[newArea favourite]);
    }
    return newArea;
}

Area.m

// 
//  Area.m
//  MappApp
//
//  Created by Matthew Fellows on 27/07/2011.
//

#import "Area.h"


@implementation Area 

@synthesize height;
@synthesize areaId;
@synthesize xPos;
@synthesize areaName;
@synthesize width;
@synthesize areaText;
@synthesize imageName;
@synthesize yPos;
@synthesize childAreas;
@synthesize parentArea;
@synthesize areaImages;
@synthesize favourite;

- (void)addChildAreasObject:(NSManagedObject *)value{
    if (childAreas == nil)
    {
        childAreas = [[NSMutableSet alloc] init];
    }
    [childAreas addObject:value];
}

- (void)addAreaImagesObject:(NSManagedObject *)value{
    if (areaImages == nil)
    {
        areaImages = [[NSMutableSet alloc] init];
    }
    [areaImages addObject:value];
}

@end

Area.h

//
//  Area.h
//  MappApp
//
//  Created by Matthew Fellows on 27/07/2011.
//

#import <CoreData/CoreData.h>


@interface Area :  NSManagedObject  
{
    NSMutableSet* areaImages;
    NSMutableSet* childAreas;
}

@property (nonatomic, retain) NSNumber * height;
@property (nonatomic, retain) NSNumber * areaId;
@property (nonatomic, retain) NSNumber * xPos;
@property (nonatomic, retain) NSString * areaName;
@property (nonatomic, retain) NSNumber * width;
@property (nonatomic, retain) NSString * areaText;
@property (nonatomic, retain) NSString * imageName;
@property (nonatomic, retain) NSNumber * yPos;
@property (nonatomic, retain) NSMutableSet* childAreas;
@property (nonatomic, retain) NSManagedObject * parentArea;
@property (nonatomic, retain) NSMutableSet* areaImages;
@property (nonatomic, retain) NSNumber* favourite;

@end


@interface Area (CoreDataGeneratedAccessors)
- (void)addChildAreasObject:(NSManagedObject *)value;
- (void)removeChildAreasObject:(NSManagedObject *)value;
- (void)addChildAreas:(NSSet *)value;
- (void)removeChildAreas:(NSSet *)value;

- (void)addAreaImagesObject:(NSManagedObject *)value;
- (void)removeAreaImagesObject:(NSManagedObject *)value;
- (void)addAreaImages:(NSSet *)value;
- (void)removeAreaImages:(NSSet *)value;

@end
  • 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-25T23:31:21+00:00Added an answer on May 25, 2026 at 11:31 pm

    You have @synthesized your accessors for what are presumably managed object properties. This means they won’t be passing through the correct core data accessors and will not be updating your model properly. @dynamic should be used to tell the compiler that the proper accessors will be available at run time (the core data framework will be providing them).

    I think with what you have now you have basically made all of your attributes transient.

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

Sidebar

Related Questions

I have a fairly simple iPhone app that downloads a set of UITableView results
I have a fairly simple set of functionality for which I have multiple implementations,
I have a fairly simple iPhone application that I want to have run on
I have a fairly simple requirement for a query API which I need to
I have a fairly simple android app, it gets protobuf data from a web
I have a fairly image-intensive iPhone app, and I'm looking to store remotely downloaded
I have a fairly simple view hierarchy in my iPad app. Window -> RootView
I have some fairly simple code using Protobuf.net, which is throwing a very odd
I'm porting a fairly simple iPhone Navigation based app to a Split View iPad
I have a fairly simple MFC app that just defines its own sub-classes of

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.