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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:31:20+00:00 2026-06-04T14:31:20+00:00

I understand that this may not necessarily apply to just @properties, but they would

  • 0

I understand that this may not necessarily apply to just @properties, but they would be the most common use case. If there is, for example:

@property (strong) NSObject *object;

...

@synthesize object = _object;

It is possible to initialise it in the init method of the class it is declared in like so:

- (id)init {
    self = [super init];
    if (self) {
        _object = [[NSObject alloc] init];
    }
}

or override the getter and initialise it upon first use:

- (NSObject *)object {
    if (!_object) {
        _object = [[NSObject alloc] init];
    }
    return _object;
}

Which of these is it better to use? Does this depend on the use scenario (e.g. does the object the property is declared in have multiple initialisers, or the type of the property, how it’s used, etc.)?

The real advantage I see in overriding the getter is that the property will only be allocated when it is needed, but a disadvantage would be that the first access would be slower.

On a side note, when accessing properties in the init method, is it better to access them as self.object or _object?

  • 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-04T14:31:21+00:00Added an answer on June 4, 2026 at 2:31 pm

    personally i find initializing in the init method is better, the life expectancy of the object is then more clear and also consider if the init fails for the object, isn’t it better to get that at the init than when you do a get?

    i also prefer to use self.object for properties because it uses the getter and setter of the object and the “self.” makes it clear and to avoid situations where a retain is needed or not. sure in some cases like in your example it may cause a couple more lines of code but i rely on the compiler to optimize the code.

    e.g.

    yourobjclass* tmp = [[yourobjclass alloc] init];
    self.object = tmp;
    [tmp release];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I understand that this isn't necessarily the best style question for stackoverflow but with
I understand that this question may be subjective, this is why I need an
I understand that 2 options are available: Non-persistent Persistent But what does this actually
I just discovered this component and started working with it. I understand that the
Depending on your interpretation this may or may not be a rhetorical question, but
This question is jQuery oriented, but not necessarily exclusively. The short question: Can synchronous
I understand that this question could be answered with a simple sentence and that
I understand that this can be done at release using the maven-gpg-plugin. However, I
I'll start of by saying that I understand that this topic is complicated and
I am very new to Silverlight development. I understand that this is client side

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.