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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:57:25+00:00 2026-06-14T20:57:25+00:00

I need to use a method that returns several strings, different ones, according to

  • 0

I need to use a method that returns several strings, different ones, according to a value.
My code looks like:


- (void) returnStringsAccordingToSet:(NSString *)string1: (NSString *)string2: (NSInteger)setNo { switch (setNo){ case 1: if (generalStringSettings){ string1 = @"The first string"; string2 = @"The second string"; } else { string1 = @"The first other string"; string2 = @"The second other string"; } break; case 2: ... break; case 3: ... break; } }

I call that method with:

NSString *firstString = [[NSString alloc]init]; NSString *secondString = [[NSString alloc]init]; NSUInteger set = 1; [self getStringsAccordingToSet: firstString: secondString: set];

I can’t get it to work! All I get is empty strings. I’ve got a feeling that the call for the strings is somewhat wrong. Please help.

  • 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-14T20:57:26+00:00Added an answer on June 14, 2026 at 8:57 pm

    You could do this by filling a NSArray, but just to show how C works I’ll show the error that you made.
    string1 and string2 are just pointers, so you can pass either mutable or immutable strings as arguments.But the original pointer never gets modified, for example:

    NSString* string1=@"Hello";  // Let's suppose string1 is on the 0x8000 address
                                 // And points to the 0x9000 address
    NSString* string2=@"How are you?";  // string2: 0x1000 , pointing to 0x2000
    [self returnStringsAccordingToSet: string1: string1 string2: string2];
    

    Then when you call a method a copy is made for every pointer that you pass to the method:

    - (void) returnStringsAccordingToSet:(NSString *)string1: (NSString *)string2: (NSInteger)setNo {
    // string1 and string2 both point on the same address, but they are other pointers
    // for example string1 is on 0x7000 and string2 on 0x7400, pointing to 0x9000
    // and 0x2000
        switch (setNo){
            case 1:
                if (generalStringSettings){
                    string1 = @"The first string";  // You just create another instance
                    string2 = @"The second string"; // of the string, but the original
                    // pointers aren't affected
                } else {
                    string1 = @"The first other string";
                    string2 = @"The second other string";
                }
                break;
            case 2:
                 ...
                 break;
            case 3:
                 ...
                 break;
        }
    }
    

    The solutions:

    1. Pass a NSMutableString as argument and instead of assigning them, just modify the contents;
    2. Pass a pointer to pointer;
    3. Return a NSArray containing the new strings.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following method that returns void and I need to use it
I need to define the constant in the module that use the method from
I need use this method with three distinct classes: Orders, Customers, Suppliers public void
I need to use method like: DoSomething<(T)>(); But i don't know which Type i
I'm writing the code for a controller method and I need to use it
In my code I need to use an IEnumerable<> several times, resulting in the
I need to use a class callback method on an array inside another method
I really need to use $this->Session->read('id') in one of the model's method therefore I
This is a design question: when do I need to create/use a static method
I have use the TryUpdateModel method on the controllers but now I need to

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.