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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:10:34+00:00 2026-06-04T03:10:34+00:00

I have the following in a subclass of UIViewController; – (id) initWithFullScreen { self

  • 0

I have the following in a subclass of UIViewController;

- (id) initWithFullScreen
{
    self = [super initWithNibName:nil bundle:nil];

    if (self) 
    {
        _fullScreen = YES;
    }

    return self;     
}
- (id) init
{
    self = [super initWithNibName:nil bundle:nil];

    if (self) 
    {
        _fullScreen = NO;
    }

    return self; 
}

- (id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{
    return [self init];
}

As you can see they aren’t all chained together like recommended as there are two initializers that call the super classes designated initializer. Is this OK to do?

  • 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-04T03:10:35+00:00Added an answer on June 4, 2026 at 3:10 am

    Yes, it’s OK.

    A designated initializer isn’t part of the Objective-C language, it’s just a convention. In general, if you route everything through one init method, your don’t have to worry about duplicating code across all the other convenience init methods that you might want to offer.

    It also lets you know which init method you should call on the superclass when you want to create a subclass. (Your third init method, initWithNibName... violates this rule, actually. Instead of calling the superclass’s designated initializer, you’re just calling init.)

    In your case, declaring an initializer with the method signature initWithFullScreen:(BOOL)fullScreen and designating it the designated initializer is probably the way to go. And within that you make sure you call the superclass’s designated initializer, which you are.

    You could then create convenience initializers: initWithFullScreen and initWithoutFullScreen if you wanted to; they would both just call your designated initializer. For example:

    - (id)initWithoutFullScreen
    {
        return [self initWithFullScreen:NO];
    }
    

    So, it’s OK to break the convention. You may have your reasons. But it’s generally easier to keep your code organized if you stick to it.

    Amendment

    For extra credit, consider the NSCoding protocol, which requires classes to have an initWithCoder: method. One might say it violates the rule, since classes which adopt NSCoding and whose superclasses also adopt NSCoding must be prepared to have two paths to initialization: an initWithCoder: method which calls [super initWithCoder:coder] and the regular designated initializer.

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

Sidebar

Related Questions

I have the following code in my UIViewController subclass, however the willAnimateROtationToInterface is never
I have the following code in a UIViewController subclass: MyViewController *viewController = [[MyViewController alloc]
I have a UIViewController subclass called TripViewController. This class has the following method: -
I have the following code in an NSView subclass: - (id)forwardingTargetForSelector:(SEL)aSelector { if ([super
I have the following subclass: class UserProfile(User): user = models.OneToOneField(User, parent_link=True) And an UserProfileAdmin:
I have a subclass of QTableWidget with the following code: connect(this, SIGNAL(cellChanged(int, int)), this,
I have the following setup: A subclass of UISplitViewController that creates the master and
I have the following code in a UIView subclass that will move it off
Let's say I have the following headers: @interface SuperClass : NSObject @interface SubClass :
I have a UIViewcontoroller subclass and the following code is in my viewdidload ,

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.