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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:29:57+00:00 2026-05-30T09:29:57+00:00

Just to confirm is that the correct way to create designated initializer in Objective-C

  • 0

Just to confirm is that the correct way to create designated initializer in Objective-C ?

Is this the correct way to init the ivars ?

Can you suggest me what to improve ?

Person.h

@interface Person : NSObject 


@property (nonatomic, retain) NSString *name;
@property (nonatomic, assign) int age;
@property (nonatomic, assign) NSString *sex;
@property (nonatomic, assign) int weight;

-(id)initWithName:(NSString *)name;
-(id)initWithName:(NSString *)name age:(int)age;
-(id)initWithName:(NSString *)name age:(int)age sex:(NSString *)s;
-(id)initWithName:(NSString *)name age:(int)age sex:(NSString *)s andWeight:(float)w;


@end

Person.m

@implementation Person

@synthesize name = _name;
@synthesize sex = _sex;
@synthesize age = _age;
@synthesize weight = _weight;

-(id)initWithName:(NSString *)name age:(int)age sex:(NSString *)s andWeight:(float)w
{
    if(self = [super init])
    {
        [self setName:name];
        [self setAge:age];
        [self setSex:s];
        [self setWeight:w];
    }
    return self;
}

-(id)initWithName:(NSString *)name age:(int)age sex:(NSString *)s
{
    return [self initWithName:name age:age sex:s andWeight:0];
}

-(id)initWithName:(NSString *)name age:(int)age
{
    return [self initWithName:name age:age sex:0];
}

-(id)initWithName:(NSString *)name
{
    return [self initWithName:name age:0];
}

-(id)init
{
    return [self initWithName:nil];
}

Thanks in advance !

  • 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-30T09:29:59+00:00Added an answer on May 30, 2026 at 9:29 am

    It is correct in my opinion. You can improve efficiency by calling to the main init method from any other one, so you don’t chain calls, but I think there are not a big difference.

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

Sidebar

Related Questions

Just want to confirm that I have this correct, and would like to see
This may seem obvious to most people, but I'm just trying to confirm that
Want to just confirm on following. Please verify if this is correct: 1. As
I want to write something that acts just like confirm() in javascript, but I
I just wanted to confirm if this was true or not - I remember
I just want to confirm that I'm understanding correctly, in Interface Builder the Class
I'm just wondering if anyone else has seen this and if so, can you
I would like to confirm that the following analysis is correct: I am building
Can someone please confirm to me that when my application is written in .NET
I've recently started creating a WPF application, and am just hoping that someone can

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.