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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:54:26+00:00 2026-06-08T19:54:26+00:00

Possible Duplicate: Why should I call self=[super init] I been reading a book of

  • 0

Possible Duplicate:
Why should I call self=[super init]

I been reading a book of Objective C, and to create a class that contains other classes (composition) it uses the self = [super init]

- (id) init
{
    if (self = [super init]) {
        engine = [Engine new];

        tires[0] = [Tire new];
        tires[1] = [Tire new];
        tires[2] = [Tire new];
        tires[3] = [Tire new];
    }

    return (self);

} // init

And when he is creating another classes he doesn’t include this init method, i understand that it need to initialize the instance objects it will be using, but i don’t understand why is he putting the self = [super init] and when a class needs this statement.

@interface Tire : NSObject
@end // Tire


@implementation Tire

- (NSString *) description
{
    return (@"I am a tire. I last a while");
} // description

@end // Tire
  • 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-08T19:54:27+00:00Added an answer on June 8, 2026 at 7:54 pm

    new is a class method that simply tells a class to perform alloc / init on itself. It is documented here. The code above could be rewritten as:

    - (id) init 
    { 
        if (self = [super init]) { 
            engine = [[Engine alloc] init]; 
    
            tires[0] = [[Tire alloc] init]; 
            tires[1] = [[Tire alloc] init]; 
            tires[2] = [[Tire alloc] init]; 
            tires[3] = [[Tire alloc] init]; 
        } 
    
        return (self); 
    
    } 
    

    And it would have exactly the same effect, but involves more typing.

    Within the Engine and Tire classes, their init methods (if implemented) will be using self = [super init]. If your class does not do anything special in its init method, you don’t need to implement one, but if you do implement one, you must use self = [super init] because you need the object to be created properly, and your superclass may be doing important work in its init method.

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

Sidebar

Related Questions

Possible Duplicate: Tasks should show up only if the user has been assigned it
Possible Duplicate: Why should the interface for a Java class be prefered? When should
Possible Duplicate: Understanding NSString comparison in Objective-C Was just reading up about equality vs
Possible Duplicate: Close and Dispose - which to call? Hi, After reading some web
Possible Duplicate: Should one call .close() on HttpServletResponse.getOutputStream()/.getWriter()? Am I responsible for closing the
Possible Duplicate: What should main() return in C/C++? What does main return? I've been
Possible Duplicate: Where should I call Free() function? When I used valgrind --leak-check=full --show-reachable=yes
Possible Duplicate: Timeout on a Python function call I want to implement that when
Possible Duplicate: Understanding Python super() Class B subclasses class A , so in B's
Possible Duplicate: Why should the interface for a Java class be prefered? I m

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.