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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:56:57+00:00 2026-06-07T07:56:57+00:00

As Objective-C has evolved (I use it exclusively with xcode/ios for iPhone/iPad development), there

  • 0

As Objective-C has evolved (I use it exclusively with xcode/ios for iPhone/iPad development), there seems to be many different ways you can layout your class instance variables. Is there a ‘best practice’ way that’s become common consensus? (I realise Apple demo/example code is all over the place in terms of style)

In particular the idea of handling private variables. Here are a number of ways I’ve seen to manage some instance variables for a class (I’ve left out the interface/implementation for brevity) – and I’m not even including the use of underscore named synthesized properties.

.h

@property (nonatomic, strong) NSString *aString;

.m

@synthesize aString;

- (void)aMethod {
   aString = @"Access directly, but if I don't have custom getter/setters and am using ARC, do I care?";
   self.aString = @"Access through self";
}

Or this:

.h

@property (readonly) NSString *aString;

.m

@property (nonatomic, strong) NSString *aString;
...
@synthesize aString;

Or this:

.m

@interface aClass {
 NSString *aPrivateString;
}

- (void)aMethod {
  aPrivateString = @"Now I have to access directly, but is this atomic/nonatomic?";
}

I don’t want this question to turn into a style argument, but it seems to me there should be a “if you’re not doing something specific or complex or weird, use this method for defining your class variables” standard.

  • 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-07T07:56:59+00:00Added an answer on June 7, 2026 at 7:56 am

    I’d prefer use the following convention for public and private ivars/properties:

    .h

    @property (nonatomic, strong) NSString *publicString;
    

    .m

    @implemention aClass 
    {
      NSNumber *_privateNumber;
    }
    @synthesize publicString = _publicString;
    

    This way everything starting with _ is an ivar (_publicString is the underlying ivar for the property, this prevents me from using publicString while I want to use self.publicString).

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

Sidebar

Related Questions

I am in the process of building my first iPhone app (xCode,objective-c) which has
I want to use/reuse C++ object with Objective-C. I have a hello.h that has
Using Iphone and Objective C Im trying to find what plane has been clicked/touched
I am new to Objective-C and iOS development and I'm not sure if I'm
How can I programmatically (Objective-C) whether an iPad has a Retina display?
I recently started to develop an iPhone App. Coming from C#, Objective-C has some
I have a table called objectives, each objective has zero to many cause-effect relationships
I'm learning Objective C to program on iOS. I know it has something to
With last version of iOS Apple has implemented Automatic Reference Counting for Objective-C, but
Something that has piqued my interest is Objective-C's BOOL type definition. Why is it

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.