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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:16:19+00:00 2026-05-23T00:16:19+00:00

I have a question about writing your own init methods in objective-c. I’ve read

  • 0

I have a question about writing your own init methods in objective-c. I’ve read a few different books and have seen a couple of ways to do it but the consensus is the right way to do it is like this:

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

    }
    return self;
}

I’m a little confused about the line “self = [super init]”. My understanding is that, there’s no guarantee that [super init] will return the class that you expect it to. I think this is called “class clusters”. But in the normal case, where it does return the class you expect it to, if I set self to point to a class that is returned to me, aren’t I just saying that self is referring to an object of a different class rather than the class that I’m in the init method of?

To summarize, why set self to be the superclass vs the actual class I’m in?

From a blog I read:

The textbook reason is because [super
init] is permitted to do one of three
things:

1) Return its own receiver (the self
pointer doesn’t change) with inherited
instance values initialized. 2) Return a
different object with inherited
instance values initialized. 3) Return
nil, indicating failure. In the first
case, the assignment has no effect on
self…

“The assignment has no effect on self” is what confuses me. Why does it have no effect? If I set something = to something else, shouldn’t that have an effect?

  • 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-23T00:16:20+00:00Added an answer on May 23, 2026 at 12:16 am

    To summarize, why set self to be the superclass vs the actual class I’m in?

    This is the Apple suggested way to do things, specifically due to the case of class clusters, as you say.

    In general, you should not worry about the fact that self might be of a different class in the “normal” case.

    self simply identifies the object you are, not the class (the class is actually a different object in the runtime). If you think of OO inheritance properties, it is at the same time an object of its class and of its superclass (if it is clear what I am trying to say). There is no contradiction in the “normal” case, since the value of self does not change.

    Also, you can think of self as a special pointer to your object. In the cluster case, self can change, that is the reason why it can happen that its class change.

    Hope this helps clarifying things. You will also find an interesting reading in this article by Wil Shipley.

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

Sidebar

Related Questions

I'm writing an app in C# (.net 3.5) and I have a question about
I have a question about vector push_back() .I am writing a code to acquire
I'm new to Stack Overflow, but I have a question about writing some Java
I have question about NSView: Imagine a Custom View where the mouseDown, mouseDrag and
I have a question about using streams in .NET to load files from disk.
I have a question about best practices regarding how one should approach storing complex
I have a question about locking. This doesn't have to be only about record
I have a question about how to deploy WPF application into a PC without
I have a question about using os.execvp in Python. I have the following bit
I have a question about using new[] . Imagine this: Object.SomeProperty = new[] {string1,

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.