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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:14:39+00:00 2026-06-06T17:14:39+00:00

I have the following code that saves an object to a file… -(int) saveObject:

  • 0

I have the following code that saves an object to a file…

-(int) saveObject: (id)object forKey: (NSString *) key 
{
    //save object into file

    NSLog(@"PRESENT");
    if(filePath == nil) 
    {
        [self setFilePath:nil];
    }

    mainDict = [NSMutableDictionary dictionaryWithContentsOfFile:filePath];
    if(mainDict == nil) 
    {
        mainDict = [[NSMutableDictionary alloc] init];
    }

    [mainDict setObject:object forKey:key];

    if(![mainDict writeToFile:filePath atomically:YES]) 
    {
        return 2; //ERROR could not write object to file
        if(object == nil) {
            return 3;
        }
        if(key == nil) {
            return 4;
        }
    } 
    else 
    {
        if(shouldUseCache == YES) {
            cacheStatus = 2; //New Caches need to be updated
        }
        return 1; //SUCCESS object saved to file
    }

    //RETURN KEY's
    // *1 SUCCESS object saved to file
    // *2 ERROR could not write object to file
    // *3 ERROR object variable = nil
    // *4 ERROR key variable = nil
}

As you can see the method should clearly return a number between 1 and 4 but when I call the method in my view controller I get 0???

The weirdest part is that I don’t even receive the NSLog(@”Present”) in my console???

What is the problem and what causes this???

Here is my simple view controller…

NSLog(@"%d",[mainDict saveObject:@"HELLO" forKey:@"foo"]);

My .h file as well…

#import <UIKit/UIKit.h>
#import "ObjectSaver.h"

@interface ViewController : UIViewController {
    ObjectSaver *mainDict;
}
  • 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-06T17:14:43+00:00Added an answer on June 6, 2026 at 5:14 pm

    Just to start: this statement doesn’t do anything:

     if(filePath == nil) {
         [self setFilePath:nil]; }
    

    If your NSLog isn’t getting hit, then the function doesn’t get called at all. Have you put a breakpoint into the function and debugged to see if it is actually ever entered?

    Also as the comments say, your function will currently never return 3 or return 4. For it to be able to do so, return 2 should be moved after those 2 if blocks so that it can be the default error if the other 2 are not valid.

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

Sidebar

Related Questions

I have the following code that fails when i run it. my .h file:
I have the following code that returns a .CSV file when a link is
I have following code that I am compiling in a .NET 4.0 project namespace
I have following code that does not work due to a being a value
I have following code that does not work: I never get to goToFoodDetail .
I have following code snippet that i use to compile class at the run
I have the following code that has @item.ID from razor: <a href=# id=deleteitem(@item.ID)>Delete</a> When
I have the following code that gets the MAC address of an interface: static
I have the following code that opens a new popup window while disabling the
I have the following code: SaveFileDialog saveGC1File = new SaveFileDialog(); private void GCSavePlacementOneButton_Click(object sender,

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.