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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:19:00+00:00 2026-06-06T19:19:00+00:00

Below is the code in my singleton to add a string to an array.

  • 0

Below is the code in my singleton to add a string to an array. The first NSLog returns the correct string but the second NSLog does not and returns null. If there is any relevant code I need to add let me know. Thanks.

 +(void) addArray:(NSString *)string
{
    NSLog(@"%@",string);

    Singleton *shared = [Singleton sharedManager];
    [shared.array addObject:string];

    NSLog(@"array: %@", shared.array);
}

I added this code to my singleton.m

- (id)init
{
    self = [super init];

    if (self) {
        // Work your initialising magic here as you normally would
        array = [[NSMutableArray alloc]init];
    }

    return self;
}

In another part of my program I run this code and it prints out the correct information

+(void) setPoints:(int) points
{
    Singleton *shared = [Singleton sharedManager];
    shared.points = points;
    NSLog(@"%d",shared.points);
}

Here is my Singleton method

+ (Singleton *)sharedManager
{
    static Singleton *sharedInstance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedInstance = [[Singleton alloc] init];
        // Do any other initialisation stuff here
        array = [[NSMutableArray alloc]init];
    });
    return sharedInstance;
}
  • 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-06T19:19:01+00:00Added an answer on June 6, 2026 at 7:19 pm

    It’s possible that you forgot to alloc-init array in your Singleton init.

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

Sidebar

Related Questions

Below code not work, but it's work fine for jsf1.2. Now the framework is
HI: Below code is from RequestFactoryEditorDriver: /** * Returns a new array containing the
The code below does NOT work: Cause: I assume I tracked down the cause
In below code when I click 'Vote' a vote results screen is displayed but
Below code instantiates a derived singleton object based on environment variable. The compiler errors
Below is the code for a singleton class class single{ private: int i; single(int
I can get the first record back from the code below in SQL Server
the code below is how i implement singleton with metaclass, and it works well
I am using the below code for a core data singleton. Below is my
I have some code as shown below. I guess it is Singleton pattern. Why

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.