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

  • Home
  • SEARCH
  • 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 6699757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:44:00+00:00 2026-05-26T06:44:00+00:00

EDIT: Problem solved! After cleaning and rebooting it just disappeared! I don’t know what

  • 0

EDIT: Problem solved! After cleaning and rebooting it just disappeared! I don’t know what caused this!

This has caused me headaches for a full day now:

In Xcode 3.2 everything worked excellent. Then I switched to 4.2 and suddenly a class inheritance does not work anymore.

I have a class TheSuperclass and TheSubclass : TheSuperclass. To simplify testing, I really created them like this. There’s no more code than what you can see here:

// TheSuperclass.h
@interface TheSuperclass : NSObject {

}

// subclasses must override this method
- (id)returnSomethingUseful;

@end

// TheSuperclass.m
#import "TheSuperclass.h"

@implementation TheSuperclass
- (id)returnSomethingUseful {
    NSLog(@"Dude, you have to override -returnSomethingUseful");
    return nil; // subclasses override this method!
}


- (id)init {
    if ((self = [super init])) {
            obj = [self returnSomethingUseful]; // TEST
        NSLog(@"TheSuperclass initialized: %@", obj);
    }
    return self;
}
@end

// TheSubclass.h
#import "TheSuperclass.h"

@interface TheSubclass : TheSuperclass {

}

@end

// TheSubclass.h
#import "TheSubclass.h"

- (id)returnSomethingUseful {
    NSLog(@"Correct method called!");
    return usefulObject;
}

TheSubclass *foo = [[TheSubclass alloc] init]; // remember: init of superclass calls the method
// Getting the NSLog: "Dude, you have to override -returnSomethingUseful"


id bar = [foo returnSomethingUseful]; // now call it directly on foo
// Getting the NSLog: "Correct method called!"

TheSuperclass declares a template method, that is, a method which just does nothing, returns nil and is intended for subclassing:

- (id)returnSomethingUseful {
    NSLog(@"Dude, you have to override -returnSomethingUseful");
    return nil; // subclasses override this method!
}

In TheSubclass, I simply override that template method. And of course I COPIED the implementation out of TheSuperclass to get it 100% right. No typo. That’s a checked fact. Looks like this:

- (id)returnSomethingUseful {
    NSLog(@"Correct method called!");
    return usefulObject;
}

In the implementation of TheSuperclass a piece of code calls [self returnSomethingUseful] in order to get that object from the template method. It’s a great pattern and I have used it a lot. It always worked exactly like this.

But now it appears that even though I create an instance of TheSubclass, it always calls the WRONG method. The one from TheSuperclass, instead of the one it should (which is the overwriding method of course)

I’ve checked that at least 100 times! Seriously, it is an instance of TheSubclass. It calls the init method of TheSuperclass giving me NSLogs.

Now the really strange part: When I call that method on my TheSubclass object “from outside”, it works:

TheSubclass *foo = [[TheSubclass alloc] init];
id bar = [foo returnSomethingUseful];
// Getting the NSLog: "Correct method called!"

So to emphasize it: When I call [self returnSomethingUseful] from within the implementation of TheSuperclass, it calls the WRONG implementation (which is the one of the superclass, rather than the overwritten one in the subclass.

So how can I work around this? Where does this possibly come from? Is this a problem in the runtime, maybe caused by an error in the compiler?

  • 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-26T06:44:01+00:00Added an answer on May 26, 2026 at 6:44 am

    LLVM clearly is able to implement simple subclassing correctly. Thousands of programs use it every day, so this is not a problem to be worked around if you are writing standard code (not trying anything tricky or undocumented). Here are the things you should do:

    • Reboot. Xcode pretends that you don’t have to reboot after install. You do in my experience. It solves 90% of problems after upgrading Xcode.
    • Clean and rebuild. This is less likely to fix it because going from 3.2 to 4.2 puts the derived files in completely different places anyway. But it’s worth trying.
    • Check [self class] to make sure you really are what you think you are.
    • Verify that you never mess with the isa pointer (easy to find; search for ->isa in your code).
    • Check your init. This is the most likely place to have done something over-tricky. Make sure you’re following the simple patterns.
    • Derive the simplest form of the problem and post some code that demonstrates it. From your description, this should be possible to do in very few lines of code. Attempting to create this simplified version will more often than not show you where your mistake is.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: This problem has been solved. See below. Hey all. I'm building an iPhone
Edit : The bug that caused this problem has been fixed. The @version tag
MAJOR EDIT: Problem was solved after reading Will Dean's comment. The original question is
[Edit: This problem applies only to 32-bit systems. If your computer, your OS and
Most of you probably know the following problem: You edit an HTML, view the
Edit: I fixed the problem by just starting from scratch. Sorry to waste y'alls
THIRD EDIT: I now believe that this problem is due to a SOAP version
EDIT: Update - scroll down EDIT 2: Update - problem solved Some background information:
PROBLEM SOLVED: I was overlooking a very simple issue, and that is that this
I imagine this is common enough that it's a solved problem, but being a

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.