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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:26:06+00:00 2026-05-31T03:26:06+00:00

I a few simple questions to make sure I am using properties right in

  • 0

I a few simple questions to make sure I am using properties right in my application. I read a lot online but it is still unclear. Thanks a lot for any help or suggestions.

(1) I am not quite sure that the statement does, and why is it needed.

@synthesize personName = _personName; 

Why do you need the _personName variable? What is the benefit of doing that as opposed to just creating a property and synthesizing that variable personName.

@property (nonatomic, retain) NSString *personName;

(2) In my application should I be accessing the property variable self.personName or use the _personName variable. I believe the self.personName is correct by then again why is the _personName even there?

(3) Also I am a little confused to which variable I should release in dealloc() and which variable should I set to nil in viewDidLoad(). I also do not know if any changes should be made to the didReceiveMemoryWarning() method.

@interface ViewController : UIViewController
{
    NSString *_personName;
}

@property (nonatomic, retain) NSString *personName;

@end



@implementation ViewController

@synthesize personName = _personName;

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.personName = [[NSString alloc] initWithString:@"John Doe"];

    NSLog(@"Name = %@", self.personName);
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
}

- (void)dealloc
{
    [super dealloc];
}

@end
  • 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-31T03:26:08+00:00Added an answer on May 31, 2026 at 3:26 am
    @synthesize personName = _personName;
    
    1. That statement creates the accessor methods for the personName property. You’ve specified that the accessors should use an instance variable named _personName. If you just had @synthesize personName;, the accessors would use personName as the instance variable instead.

    2. You should usually use the accessor methods, as in self.personName or somePerson.personName or somePerson.personName = @"Joe";. If you don’t care what the name of the ivar that backs up the personName property, you don’t need to specify it.

    3. Use the accessors in -viewDidLoad, as in: self.personName = nil;. Same for -didReceiveMemoryWarning:. Whether to use the ivar or property in -dealloc is debatable, and to some degree a matter of taste. The main concern with using the property accessors in -dealloc is that it can cause problems if your class is subclassed and the accessors are overridden. Often, you don’t need to worry about that because you know that your class won’t be subclassed.

    4. Setting an ivar to nil after releasing is also debatable. Many people feel that it’s good style to do so, others feel like it’s a waste of time. Use your best judgement. It’s certainly not necessary, but rather something that some feel is a matter of good housekeeping.

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

Sidebar

Related Questions

I want to build a bot that asks someone a few simple questions and
I am new to TCP programming so here is a few simple questions: Client
Rather a simple question. But the implications are vast. Over the last few weeks
I am no AppleScript Jedi, I've only done a few simple things, but I
I'm an ASP.NET web part novice. I've built a few simple ones using only
I know there are a few questions floating around here on the subject, but
I'm supposed to make a simple application, an xHTML editor with some basic validation
I have found quite a few questions related to this but I haven't found
Pretty simple question. I have a few ASP RequiredFieldValdators checking some text boxes. Out
In a few simple sentences, what is a Java ClassLoader, when is it used

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.