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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:55:06+00:00 2026-06-02T06:55:06+00:00

Here is my singleton code: @synthesize listOfSites; + (id)sharedInstance { static dispatch_once_t dispatchOncePredicate =

  • 0

Here is my singleton code:

@synthesize listOfSites;

+ (id)sharedInstance
{
    static dispatch_once_t dispatchOncePredicate = 0;
    __strong static id _sharedObject = nil;
    dispatch_once(&dispatchOncePredicate, ^{
        _sharedObject = [[self alloc] init];
    });

    return _sharedObject;
}

-(id)init
{
    self = [super init];
    if (self) {
        listOfSites = [[NSMutableArray alloc] init];
    }
    return self;
}

@end

It’s pretty much textbook… however, I want to add another array, similiar to “listOfSites” (call it “listOfReadings”). The code that says “if (self)” confuses me.

How do I add another array to this code?

  • 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-02T06:55:09+00:00Added an answer on June 2, 2026 at 6:55 am

    if (self) { does nothing but to verify that the [super init] has worked – and that it hasn’t return NULL or anything…

    Other than that, you can do this normally, like :

    • declare a listOfReadings array (as an ivar/property?)
    • set it up

      listOfReadings = [[NSMutableArray alloc] init];
      

      or

      listOfReadings = [[NSMutableArray alloc] initWithObjects:nil];
      

      or (if it’s a property)

      [self setListOfReadings:[[NSMutableArray alloc] initWithObjects:nil]];
      

    Example :

    -(id) init {
        self = [super init];
        if (self) {
            listOfSites = [[NSMutableArray alloc] init];
            listOfReadings = [[NSMutableArray alloc] init];
        }
        return self;
    }
    

    after having declared the new NSMutableArray in your .h file :

    NSMutableArray* listOfReadings;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

here is code + (SalesCollection*)sharedCollection { @synchronized(self) { if (sharedInstance == nil) { [[self
Here's my singleton code (pretty much boilerplate): @interface DataManager : NSObject { NSMutableArray *eventList;
I have a a singleton class here is the code #import <Foundation/Foundation.h> #import CustomColor.h
I'm trying to pass data around objects using singleton pattern. Here is my code
I have this code running on PHP 5.2.6 class Singleton { static private $instance
I saw the following code: http://sourcemaking.com/design_patterns/singleton/cpp/1 class GlobalClass { private: int m_value; static GlobalClass
I've been looking at the article on creating static constructors in c# here: http://csharpindepth.com/Articles/General/Singleton.aspx
I was implementing a singleton pattern.Here,I am creating a new instance of Singleton* in
I've been reading about thread-safe singleton patterns here: http://en.wikipedia.org/wiki/Singleton_pattern#C.2B.2B_.28using_pthreads.29 And it says at the
The singleton is explained here: http://en.wikipedia.org/wiki/Singleton_pattern#PHP_5 . I want to use the singleton class

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.