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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:28:07+00:00 2026-06-09T23:28:07+00:00

Example iVar foo , @property (nonatomic) NSString* foo; // inside .h Option 1 @Synthesize

  • 0

Example iVar foo,

@property (nonatomic) NSString* foo; // inside .h

Option 1

@Synthesize foo; //Inside .m 

foo = [[NSString alloc] init]; // viewDidLoad method

Option 2

@Synthesize foo; //Inside .m 

self.foo = [[NSString alloc] init]; // viewDidLoad method

Option 3

@Synthesize foo = _foo; //Inside .m 

_foo = [[NSString alloc] init]; // viewDidLoad method

Why?

At so many places I have seen code which has different ways of doing init an Object in Obj – C but which one is the best practise?

  • 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-09T23:28:09+00:00Added an answer on June 9, 2026 at 11:28 pm

    In this regard, ARC is the same as MRC.

    you have specified all these take place in viewDidLoad. in that case, use the setter (Option 2).

    if you were to initialize/set in the initializer, then you would use direct access. the basic reason is that in the initializer (e.g. -init), you have a partially initialized object. during initialization, you want to focus on initializing variables your class needs or expects in order to function correctly. as well, you want to avoid side-effects you can encounter when using the accessors in partially constructed states.

    in a fully constructed state (e.g. viewDidLoad), you should relegate the implementation to the accessors for correct behavior, as specified by your object’s interface.


    Additional Reading:

    Initializing a property, dot notation

    Should I refer to self.property in the init method with ARC?

    Why would you use an ivar?

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

Sidebar

Related Questions

For example, if I have a property index and an ivar _index , is
I was wondering if I can directly alloc, init an ivar now with ARC
aclass.h @interface aClass : NSObject { NSString *name; } @property (nonatomic, retain) IBOutlet NSString
When referencing a weak ivar inside of a block in Objective-C when ARC is
For example I want to store this in an ivar: CGFloat color[4] = {red,
If I declare an ivar without property declaration, and this ivar could be used
I copied this example from this topic. It's better to release the ivar directly.
Let's begin with an example : @interface myClass : NSObject { NSString * title;
I have a property @property (strong, nonatomic, readonly) NSMutableArray* myArray; and I want to
Example Div: <div class=container> <div class=select1></div> <div class=select2></div> <div class=select3></div> </div> Now I want

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.