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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:24:42+00:00 2026-06-10T13:24:42+00:00

I have the below method and I want to call it and return the

  • 0

I have the below method and I want to call it and return the array data in another method but that does not work. but the self in the other method returns no data?

- (NSMutableArray *)glo
{
    NSMutableArray *globalarray = [[NSMutableArray array]init];
    for (int x = 0; x < 10; x++) {
        [globalarray addObject: [NSNumber numberWithInt: arc4random()%200]];
        return globalarray ;
    }
}


-(IBAction)clicked_insertsort:(id)sender{
    [self glo];
}
  • 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-10T13:24:44+00:00Added an answer on June 10, 2026 at 1:24 pm

    I really try to replace some part in your code to something like this:

    - (NSMutableArray *)glo
    {
        NSMutableArray *globalarray = [[NSMutableArray array] init];
        for (int x = 0; x < 10; x++) {
            [globalarray addObject:[NSNumber numberWithInt: arc4random()%200]];
        }
        return globalarray; // pull out from the loop
    }
    

    and this:

    -(IBAction)clicked_insertsort:(id)sender{
        NSMutableArray *array = [self glo]; // take care of the return value
        NSLog(@"array : %@", array)
    }
    

    UPDATE:

    if you want a global variable in you class you should define the following:

    @interface YourClass : NSObject {
        NSMutableArray *globalarray;
    }
    
    // ...
    
    @end
    

    and the methods will be the following (no return value needed, because the variable is available from the whole class now)

    - (void)glo {
        if (!globalarray) {
            globalarray = [NSMutableArray array];
            for (int x = 0; x < 10; x++) {
                [globalarray addObject:[NSNumber numberWithInt: arc4random()%200]];
            }
        }            
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class called Ball, and i want to call a method called
I have a class with a method called Validate that I want to test
i have a problem with my script i have a method that return a
I have a method that I use to return a dynamic query. This method
In the code below I want to call the method OpenNextPage through a call
I have this following method that connectss to db and returns a json array.
i have created a 3tier application.. where i want to call the update method
I have a xml string that return from Post method: private static void GetResponseCallback(IAsyncResult
I want to style mail body. I have tried the below methods to style
I have the below method which is meant to append information to a file

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.