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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:20:40+00:00 2026-06-13T03:20:40+00:00

I am new to iOS and passing parameters by value or reference ( I

  • 0

I am new to iOS and passing parameters by value or reference ( I am from a Java/.NEt background ) is confusing to me.
you see I have a sort of utility / Helper method that I pass to it an NSMutableDictionary, and then a file location, and ask for it yo unrchive data form the file to the dictionary I sent it.
this is the helper method :

 - (void)loadData:(NSMutableDictionary *)dictionary fromFile:(NSString *)fname  {
     dictionary = [ NSKeyedUnarchiver unarchiveObjectWithFile : [ self getFilePath:fname ] ] ;
    if ( [dictionary.allKeys count] < 1 ) {
       NSLog(@"Couldn't load file %@ ", fname);
    }  else  {
      NSLog(@"Loaded data from file %@ successfully", fname );
  }
}

now I call this method in the following line of code

      [ loadData: dataDict fromFile:@"data.archive"];

Now the problem is that by the end of the helper method , I have a variable called dictionary that does have values, but its not the original dictionary I passed from my calling line.
What Am I Doing wrong?

  • 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-13T03:20:40+00:00Added an answer on June 13, 2026 at 3:20 am

    As explained here – Passing arguments by value or by reference in objective C – in objective c parameters are passed by value and so a modification made to the parameter is modifying a value and not the actual value of the reference being passed in.

    If you want to modify your dictionary you should prefix it with an ** to pass the value of the reference and then access with *.

    - (void)loadData:(NSMutableDictionary**)dictionary fromFile:(NSString*)fname  {
    {
        *dictionary = [NSKeyedUnarchiver unarchiveObjectWithFile:[self getFilePath:fname]];
        if ([*dictionary.allKeys count] < 1) {
            NSLog(@"Couldn't load file %@ ", fname);
        }  
        else  {
            NSLog(@"Loaded data from file %@ successfully", fname);
        }
    }
    

    Note: This sort of pointer dereferencing is a little funky and should probably restricted to **Error passing. It would probably make more sense to create a new dictionary copy content and return it.

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

Sidebar

Related Questions

I'm using the new iOS 5 core data concurrency options. I have two threads:
I'm quite new here. I have a problem with the new iOS 5.1 slide-in
In new iOS 6, viewDidUnload is deprecated and we have been instructed to use
Hoping someone can help a new iOS developer out - I have a ready
I am new to iOS programming, and I am having trouble with passing data
I'm new to iOS development--I'm working on passing data between different views... Let's say
I am new to IOS programming. So far I have been programming in android.
I'm new at iOS development and after reading many tutorials about passing variables and
I'm developing a new iOS app I have a view controller in my storyboard
I'm starting to create a new iOS app, which pull and push data from

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.