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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:49:03+00:00 2026-06-01T11:49:03+00:00

I am writing a controller class for my plist, which gets called from another

  • 0

I am writing a controller class for my plist, which gets called from another class. the controller class has a read and save method, the read method opens up the plist and saves it to the documents file for reading and writing too. In this read class I put all of the values that have been saved previously into their own variables.

Then in the Save method call, which is called from another class, all the values are passed in as parameters then from there I pass the new values into the correct variables and pass that into the plist.. however I have a dictionary inside my plist and its only saving one value and the resetting the others to null.. I am wondering how do I make sure these variables keep their values?

Here is my .h

#import <Foundation/Foundation.h>

@interface EngineProperties : NSObject {

NSString *signature;
NSNumber *version;
NSNumber *request;
NSNumber *dataVersion;
NSMutableDictionary *cacheValue;
//cachevalue Items
NSNumber *man;
NSNumber *mod;
NSNumber *sub;

}

@property (copy, nonatomic) NSString *signature;
@property (copy, nonatomic) NSNumber *version;
@property (copy, nonatomic) NSNumber *request;
@property (copy, nonatomic) NSNumber *dataVersion;
@property (copy, nonatomic) NSMutableDictionary *cacheValue;
//cachevalue Items
@property (copy, nonatomic) NSNumber *man;
@property (copy, nonatomic) NSNumber *mod;
@property (copy, nonatomic) NSNumber *sub;



- (void) readPlistData;
- (void) saveData:(NSString *)methodName signature:(NSString *)pSignature Version:(NSNumber *)pVersion request:(NSNumber *)rNumber dataVersion:(NSNumber *)dvReturned cacheValue:(NSNumber *)cValue;

@end

and Here is my .m

#import "EngineProperties.h"

@implementation EngineProperties

@synthesize signature;
@synthesize version;
@synthesize request;
@synthesize dataVersion;
@synthesize cacheValue;

@synthesize man;
@synthesize mod;
@synthesize sub;



//This opens up and reads the current plist ready to be used
-(void) readPlistData
{
    // Data.plist code
    // 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"];

    // 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];
    if (!tempRoot)
    {
        NSLog(@"Error reading plist: %@, format: %d", errorDesc, format);
    }
    // assign values
    self.signature = [tempRoot objectForKey:@"Signature"];
    self.version = [tempRoot objectForKey:@"Version"];
    self.request = [tempRoot objectForKey:@"Request"];
    self.dataVersion = [tempRoot objectForKey:@"Data Version"];

    man = [cacheValue objectForKey:@"Man"];
    mod = [cacheValue objectForKey:@"Mod"];
    sub = [cacheValue objectForKey:@"SubMod"];

    cacheValue = [tempRoot objectForKey:@"Cache Value"];
}


- (void) saveData:(NSString *)methodName signature:(NSString *)pSignature Version:(NSNumber *)pVersion request:(NSNumber *)rNumber dataVersion:(NSNumber *)dvReturned 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.signature = pSignature;
    self.version = pVersion;
    self.request = rNumber;
    self.dataVersion = dvReturned;

    //do some if statment stuff here to put the cache in the right place or what have you.
    if (methodName == @"manufacturers")
    {
        self.man = cValue; 
    }
    else if (methodName == @"models")
    {
        self.mod = cValue;
    }
    else if (methodName == @"subMod")
    {
        self.sub = cValue;
    }

    self.cacheValue = [NSDictionary dictionaryWithObjectsAndKeys:
                       man, @"Manufacturers",
                       mod, @"Models",
                       sub, @"SubModels", nil];


    NSDictionary *plistDict = [NSDictionary dictionaryWithObjectsAndKeys:
                               signature, @"Signature",
                               version, @"Version",
                               request, @"Request",
                               dataVersion, @"Data Version",
                               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];

        NSString *myString = [[NSString alloc] initWithData:plistData encoding:NSUTF8StringEncoding];
        //        NSLog(@"%@", myString);
    }
    else
    {
        NSLog(@"Error in saveData: %@", error);
        //        [error release];
    }
}


@end

I am trying to find out how to keep the correct values in these three vars, man, mod, sub so I can put them into my cache value dictionary..

  • 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-01T11:49:05+00:00Added an answer on June 1, 2026 at 11:49 am

    The problem is when you are getting your data ready to create the dictionary, here:

    if (methodName == @"manufacturers")
    {
        self.man = cValue; 
    }
    else if (methodName == @"models")
    {
        self.mod = cValue;
    }
    else if (methodName == @"subMod")
    {
        self.sub = cValue;
    }
    

    This is not the correct way to compare strings (you are actually comparing the addresses of the strings so they will probably never be the same), instead you should use this:

    if ([methodName isEqualToString:@"manufacturers"])
    {
        self.man = cValue; 
    }
    else if ([methodName isEqualToString:@"models"])
    {
        self.mod = cValue;
    }
    else if ([methodName isEqualToString:@"subMod"])
    {
        self.sub = cValue;
    }
    

    Another issue is that in readPlistData you are reading the keys “Man”, “Mod”, and “SubMod” but they should be the same as what you write into the dictionary: “Manufacturers”, “Models”, and “SubModels”. (Either one could be correct, but they need to match so that you are reading and writing the same keys!)

    Lastly, are you using the same instance of EngineProperties each time that you call saveData or are you creating a new object each time? If you aren’t using the same object, then the iVars will be reset to nil each time that you call it.

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

Sidebar

Related Questions

I am new to ObjC. I have a method in my controller class called
I am writing a Controller for Codeigniter with a method named print. The name
I'm writing the code for a controller method and I need to use it
I'm writing the spec for controller: it 'should call the method that performs the
I am writing a catch all method for my controller for ajax. It is
I'm writing a plugin that adds a class method to ActionController::Base , so in
I'm writing an IO class to upload/download files to a controller over RS-232 serial.
I'm writing a front controller servlet class for webapps. The front controller is designed
I have code structure in which I have class file, template file and controller
I am writing a view controller for adding a new item to my app.

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.