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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:56:02+00:00 2026-05-21T06:56:02+00:00

I am working on a delegate class that controls several views, and find myself

  • 0

I am working on a delegate class that controls several views, and find myself switching between updating properties in the delegate and returning values from methods. What is the proper way to do this?

-(NSArray)blah{
return myarray;
}

or
-(void)blah{
[self myarray:value]
}

————— Clarification of question below

if I have a helper method that converts an NSArray into a NSDictionary
should I call my helper method and expect a return of NSDictionary, or should I update a variable in memory and return void.

  • 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-21T06:56:03+00:00Added an answer on May 21, 2026 at 6:56 am

    There’s a case for each approach, depending on what you are really doing. The two choices are:

    • It is truly a helper method, that has use in many places in your application.
    • It is specific to a single class and the dictionary is a member of that class.

    OPTION 1) If it is truly a helper method, I believe that you should return the NSDictionary from the method. I’m assuming it is newly allocated within that method.

    In other words, prefer:

    + (NSDictionary *) dictFromArray:(NSArray *);
    

    If it has utility outside of a single class, you could put it in a sensible class that collects related utility methods.

    The alternative approach of passing in an empty dictionary to be filled is practiced in C because it creates symmetry around allocating and freeing and makes it clear who owns the memory.

    In Objective-C, reference counting takes care of that, so you can avoid the extra code of allocating empty objects just to call the method.

    For example:

    NSMutableDictionary *myDict = [[NSMutableDictionary alloc] init];
    dictFromArray(myArray, myDict);
    

    When it comes to knowing who owns the object, you should stick to Objective-C conventions, where:

    + (NSDictionary *) dictFromArray:(NSArray *)array
    

    returns an autorelease object, so the caller knows they need to retain it if they want to hold a reference.

    OPTION 2) If the functionality is specific to a single class and that class has the dictionary as a member, then I would pass in the array, update the dictionary member variable using the array contents, and return void.

    Something like:

    - (void) setBlahFromArray:(NSArray *)array
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got an abstract class (Object2D), and several class that inherits Object2D (DisplayObject2D for
I'm working on a project that interfaces with Google Data APIs. I have several
Working with a SqlCommand in C# I've created a query that contains a IN
Working on a project that parses a log of events, and then updates a
I am trying to create a class that lets me call methods with a
I'm working on a project that just needs to be rewritten but that is
I'm working on an iPhone that heavily interacts with a server. I'm at the
I'm working on making an iPhone version of an Android app that I've written
I'm working with NSXMLParser that parses a xml document. You have to set the
In my program there is a BackgroundWorker class that preloads the images to BitmapImage

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.