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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:28:20+00:00 2026-06-08T01:28:20+00:00

i am working on a project in wich i want to use Singleton Pattern

  • 0

i am working on a project in wich i want to use Singleton Pattern model.
i want to any data model of my this project fallow Singleton Pattern.
i study the apple documentation regarding this

http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaDesignPatterns/CocoaDesignPatterns.html#//apple_ref/doc/uid/TP40002974-CH6-SW6

and

http://www.oodesign.com/singleton-pattern.html

http://www.daveoncode.com/2011/12/19/fundamental-ios-design-patterns-sharedinstance-singleton-objective-c/

now i know my custom object classes should fallow the main rule of allocing a object but the i need the complete implementation like using of this class object
i am new in iphone app development so if i am wrong in any place in this Question please guide

  • 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-08T01:28:21+00:00Added an answer on June 8, 2026 at 1:28 am
    static MyClass *_sharedInstance;
    
    + (MyClass *)sharedMyClass
    {
        @synchronized([MyClass class]) {
            if (_sharedInstance == nil)
                [[self alloc] init];
    
            return _sharedInstance;
        }
    
        return nil;
    }
    
    +(id) alloc
    {
        @synchronized([MyClass class]) {
            NSAssert(_sharedInstance == nil, @"Attempted to allocate a second instance of MyClass.");
            _sharedInstance = [super alloc];
            return _sharedInstance;
        }
    
        return nil;
    }
    
    + (id) allocWithZone:(NSZone *)zone 
    {
        @synchronized([MyClass class]) {
            NSAssert(_sharedInstance == nil, @"Attempted to allocate a second instance of MyClass.");
            _sharedInstance= [super allocWithZone:zone];
            return _sharedInstance;
        }
        return nil; //on subsequent allocation attempts return nil
    }
    
    - (id) copyWithZone:(NSZone *)zone 
    {
        return self;
    }
    
    - (id)retain
    {
        return self;
    }
    
    - (NSUInteger)retainCount
    {
        return NSUIntegerMax;
    }
    
    - (oneway void)release
    {
        // Do nothing
    }
    
    - (id)autorelease
    {
        return self;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a project in wich I need to return a list of
I have a working project that Im amending, it crashes after trying to use
I am working on project and ran into an issue. Now I want to
I'll try to be concise this time around! I'm still working Project Euler, this
Im working on a web project in ASP .NET MVC 2. In this project
This is supposed to be a working project from my friend. He demonstrated the
I'm new to WPF, working on my first project. I've been stuck in this
I’m working on a project where the main focus are photos. I want to
I'm curious if it is possible to move the written and fully working project
While working a project tonight, I ended up using one .js resource file for

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.