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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:24:39+00:00 2026-06-01T18:24:39+00:00

Okay I have spent the last 2 days trying to sort this one out.

  • 0

Okay I have spent the last 2 days trying to sort this one out. I have a class thats controlling my property list, It is used as a singleton class so its only instantiated once and it has one other method in it that is used to save the values to the plist.

The plist works sweet no matter what you do up untill you remove the app from the multitasking bar (i.e. close the app completely) then all of the values in the plist are reset to null.. However the plist is not lost.

So I am thinking now maybe I am overwriting the values in my plist that I have made in the root document directory for read and write capability. I am hoping with my code example you guys might be able to spot my mistake… I’m not sure what else I need to add.. if you have any question that will help you help me answer this problem then please let me know.

any help would be hugely appreciated and my children’s children’s children will be in debuted to you.

#import "EnginePropertiesController.h"

static EnginePropertiesController *sharedMyManager = nil;

@implementation EnginePropertiesController

@synthesize pSignature;
@synthesize pVersion;
@synthesize rNumber;
@synthesize dVReturned;
@synthesize cacheValue;

@synthesize manu;
@synthesize mod;
@synthesize submod;


#pragma mark Singleton Methods
+ (id)sharedManager {
    @synchronized(self) {
        if (sharedMyManager == nil)
            sharedMyManager = [[self alloc] init];
    }
    return sharedMyManager;
}
- (id)init {
    if (self = [super init]) {

            // get paths from root direcory
            NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
            // get documents path
            NSString *documentsPath = [paths objectAtIndex:0];
            // get the path to our Data/plist file
            NSString *plistPath = [documentsPath stringByAppendingPathComponent:@"EngineProperties.plist"];
            NSLog(@"myplist path read = %@", plistPath);

            // check to see if Data.plist exists in documents
            if (![[NSFileManager defaultManager] fileExistsAtPath:plistPath])
            {
                // if not in documents, get property list from main bundle
                plistPath = [[NSBundle mainBundle] pathForResource:@"EngineProperties" ofType:@"plist"];

            }

            // read property list into memory as an NSData object
            NSData *plistXML = [[NSFileManager defaultManager] contentsAtPath:plistPath];
            NSString *errorDesc = nil;
            NSPropertyListFormat format;
            // convert static property liost into dictionary object
            NSDictionary *tempRoot = (NSMutableDictionary *)[NSPropertyListSerialization propertyListFromData:plistXML mutabilityOption:NSPropertyListMutableContainersAndLeaves format:&format errorDescription:&errorDesc];
            manu = [cacheValue objectForKey:@"Manu"];
            mod = [cacheValue objectForKey:@"Mod"];
            submod = [cacheValue objectForKey:@"SubMod"];
            if (tempRoot && [tempRoot count]){
                // assign values
                self.pVersion = [tempRoot objectForKey:@"PSignature"];
                self.pVersion = [tempRoot objectForKey:@"PVersion"];
                self.rNumber = [tempRoot objectForKey:@"RNumber"];
                self.dVReturned = [tempRoot objectForKey:@"DVReturned"];
                cacheValue = [tempRoot objectForKey:@"Cache Value"];
        }
    }
    return self;
}

- (void) saveData:(NSString *)methodName pSignature:(NSString *)TemppSignature pVersion:(NSNumber *)TemppVersion rNumber:(NSNumber *)TemprNumber dVReturned:(NSNumber *)TempdvReturned cacheValue:(NSNumber *)cValue
{
    // get paths from root direcory
    NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
    // get documents path
    NSString *documentsPath = [paths objectAtIndex:0];
    // get the path to our Data/plist file
    NSString *plistPath = [documentsPath stringByAppendingPathComponent:@"EngineProperties.plist"];

    // set the variables to the values in the text fields
    self.pSignature = TemppSignature;
    self.pVersion = TemppVersion;
    self.rNumber = TemprNumber;
    self.dVReturned = TempdVReturned;

    //This checks with methodName I would like to save the value from
    //The reason for this is there are 3 different cache values I get at seperate times to save This if statment just makes sure they are in the correct order.
    if ([methodName isEqualToString:@"Getmanu"]) {
        self.manu = cValue; 
    } else if ([methodName isEqualToString:@"GetMod"]) {
        self.mod = cValue;
    } else if ([methodName isEqualToString:@"GetSubMod"]) {
        self.submod = cValue;
    }        

    //Set up cacheValue Dictionary that will be added to the property list root dictionary
    self.cacheValue = [NSDictionary dictionaryWithObjectsAndKeys:
                       manu, @"Manu",
                       mod, @"Mod",
                       subMod, @"SubMod", nil];

    //Pass appropriate values into plist
    NSDictionary *plistDict = [NSDictionary dictionaryWithObjectsAndKeys:
                               protocolSignature, @"Protocol Signature",
                               pVersion, @"Protocol Version",
                               rNumber, @"Request Number",
                               dVReturned, @"Data Version returned",
                               cacheValue, @"Cache Value", nil];


    NSString *error = nil;
    // create NSData from dictionary
    NSData *plistData = [NSPropertyListSerialization dataFromPropertyList:plistDict format:NSPropertyListXMLFormat_v1_0 errorDescription:&error];

    // check is plistData exists
    if(plistData) {
        // write plistData to our Data.plist file
        [plistData writeToFile:plistPath atomically:YES];
    } else {
        NSLog(@"Error in saveData: %@", error);
    }
}


@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-06-01T18:24:41+00:00Added an answer on June 1, 2026 at 6:24 pm

    The Problem: nil Values

    Here’s a problem: pVersion is assigned twice, while pSignature remains nil.

    self.pVersion = [tempRoot objectForKey:@"PSignature"];
    self.pVersion = [tempRoot objectForKey:@"PVersion"];
    

    This should probably be

    self.pSignature = [tempRoot objectForKey:@"PSignature"];
    self.pVersion = [tempRoot objectForKey:@"PVersion"];
    

    This in turn leads to trouble at saving time:

    NSDictionary *plistDict = [NSDictionary dictionaryWithObjectsAndKeys:
                               pSignature, @"PSignature",
                               pVersion, @"PVersion",
                               rNumber, @"RNumber",
                               dVReturned, @"DVReturned",
                               cacheValue, @"Cache Value", nil];
    

    This constructor doesn’t know how many arguments it has, it just keeps going until it hits nil. If pSignature is nil, it will save an empty dictionary.

    The Fix: Robust NSDictionary Creation

    While the immediate solution is to fix the pSignature reading, it’s always fragile to construct dictionaries using dictionaryWithObjectsAndKeys:. It’s much better to store each object individually, using setObject:forKey. This throws an exception if the object is nil, so test before calling.

    NSMutableDictionary *plistDict = [NSMutableDictionary dictionary];
    if (pSignature) [plistDict setObject:pSignature forKey:@"PSignature"];
    if (pVersion) [plistDict setObject:pVersion forKey:@"PVersion"];
    // ... and so on.
    

    The Alternative: NSCoding

    Another option for storage is to serialize. See the Archives and Serializations Programming Guide. This has tradeoffs: while saving and loading is simpler when it works, the resulting files are less human-readable.

    Debugging

    Finally, three places to put log statements, breakpoints or dialog boxes that help in cases like this:

    1. Log the dictionaries being loaded and the dictionaries being saved. If you open your app and trigger a save immediately, are the dictionaries identical?
    2. Check the first argument sent to nil-terminated methods like arrayWithObjects: and dictionaryWithObjectsAndKeys:
    3. On the simulator, log the path used for saving and open it in Finder. Is there a file there? If it’s a property list, you can open it in XCode and see if it has the content you expect.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

okay i have been trying to understand this for hours i am learning VB
Okay, so i have spent all day searching the web for why this is
I'm quite new to javascript (okay, I've spent only two days using it!). One
Okay I have a series of objects based on a base class which are
Okay so i have this code: if (isset($_GET['book'])) { $query= SELECT book_id, title, authors.`author`
Okay, so I have an issue with an AJAX request. I currently have this
Okay, here's what I'm attempting. I have a drop down list with all of
Okay, I'll simplify this post. I have a table tasks containing, for example, a
This is probably obvious, but I'm a bit of a newbie and have spent
This case is really strange, i've spent 2 whole days to get Twitter Oauth

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.