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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:40:22+00:00 2026-05-27T08:40:22+00:00

I have the following situation, i can’t resolve: @interface Deck : NSObject @interface MasterDeck

  • 0

I have the following situation, i can’t resolve:

@interface Deck : NSObject
@interface MasterDeck : Deck 
@interface PlayerDeck : Deck

Inside MasterDeck class, as part of initialization, i call

[self cutDeckImageIntoCards]; // We don't get to execute this method

Call results in an error [PlayerDeck cutDeckImageIntoCards]: unrecognized selector sent to instance

Indeed, PlayerDeck does not have this method .. but why is it being called at all?

After looking at MasterDeck’s initialization i added a few debugging statements:

static MasterDeck *gInstance = NULL;

+(MasterDeck *) instance {
    @synchronized(self) {
        if (gInstance == NULL) {
            gInstance = [[self alloc] init];
        }
    }

    return gInstance;
}

-(id) init {

    if (gInstance != NULL) {
        return gInstance;
    }

    // MasterDeck
    self = [super init];  
    // PlayerDeck

    if (self) {
       // Lots of stuff
       [self cutDeckImageIntoCards]
       // Some more stuff
     }

    gInstance = self;
    return gInstance;
}

Ok, so MasterDeck is PlayerDeck because’ Deck thinks it is a PlayerDeck … Deck confirms

Deck is created as follows:

static Deck *gInstance = NULL;

+(Deck *) instance {
    @synchronized(self) {
        if (gInstance == NULL) {
            gInstance = [[self alloc] init];
        }
    }

    return gInstance;
}

-(id) init {

    if (gInstance != NULL) {
        return gInstance;
    }

    self = [super init];

    if (self) {               
       // Do something
    }

    NSLog(@"Deck thinks it's a %@", [[self class ]description]); // PlayerDeck

    gInstance = self;
    return gInstance;
}

So, again

  • @interface Deck : NSObject

Assuming above Singleton Implementation, why would Deck think it’s actually a PlayerDeck?

  • 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-05-27T08:40:23+00:00Added an answer on May 27, 2026 at 8:40 am

    So the way you’ve written this, if you create the PlayDeck instance first, then the Deck instance is now a PlayDeck.

    And then if you go to create the MasterDeck instance, your call to [super init] dutifully returns that previous PlayDeck instance.

    So why is Deck a singleton at all? Deck has two subclasses that are singletons, but are you really looking for a singleton Deck also?

    At a minimum, you can make this sort of work by not setting gInstance from within each init. Let the class method do that. Just return self from each of the init’s. Also, remove the check for gInstance being not null, other Deck’s init will always return Deck’s instance once you have an instance of Deck.

    But beyond that, I would rethink this idea a bit. Hope that helps.

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

Sidebar

Related Questions

I have following situation. In a constructor of a pseudo class I attach a
I have following situation (simplified, of course): MyDomain.groovy: class MyDomain { MyAnotherDomain anotherDomain //
I have the following situation: class A { public: A(int whichFoo); int foo1(); int
I have the following situation: // A public interface of some kind public interface
I have the following situation: <nav id=access role=navigation> <div class=menu> <ul> <li class=page_item><a href=#pricing
I have a problem with JPA 1.0 (OpenJPA) Following situation @Entity public class A{
What happens when I have the following situation: class A: holds on to dynamically
I have following situation. I have a class for accounts, each account has a
I have the following situation: Assembly A - Class library, contains my control Control
Suppose I have the following situation: 9 class Program 10 { 11 public static

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.