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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:02:47+00:00 2026-05-30T18:02:47+00:00

If I create a @property and synthesize it, and create a getter and setter

  • 0

If I create a @property and synthesize it, and create a getter and setter as well like so:

#import <UIKit/UIKit.h>
{
    NSString * property;
}

@property NSString * property;

--------------------------------

@implementation

@synthesize property = _property

-(void)setProperty(NSString *) property
{
    _property = property;
}

-(NSString *)property
{
    return _property = @"something";
}

Am I correct in assuming that this call

-(NSString *)returnValue
{
    return self.property; // I know that this automatically calls the built in getter function that comes with synthesizing a property, but am I correct in assuming that I have overridden the getter with my getter? Or must I explicitly call my self-defined getter?
}

is the same as this call?

-(NSString *)returnValue
{
    return property; // does this call the getter function or the instance variable?
}

is the same as this call?

-(NSString *)returnValue
{
    return _property; // is this the same as the first example above?
}
  • 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-30T18:02:49+00:00Added an answer on May 30, 2026 at 6:02 pm

    There are a number of problems with your code, not least of which is that you’ve inadvertently defined two different instance variables: property and _property.

    Objective-C property syntax is merely shorthand for plain old methods and instance variables. You should start by implementing your example without properties: just use regular instance variables and methods:

    @interface MyClass {
        NSString* _myProperty;
    }
    - (NSString*)myProperty;
    - (void)setMyProperty:(NSString*)value;
    
    - (NSString*)someOtherMethod;
    @end
    
    @implementation MyClass
    
    - (NSString*)myProperty {
        return [_myProperty stringByAppendingString:@" Tricky."];
    }
    
    - (void)setMyProperty:(NSString*)value {
        _myProperty = value; // Assuming ARC is enabled.
    }
    
    - (NSString*)someOtherMethod {
        return [self myProperty];
    }
    
    @end
    

    To convert this code to use properties, you merely replace the myProperty method declarations with a property declaration.

    @interface MyClass {
        NSString* _myProperty;
    }
    @property (nonatomic, retain) NSString* myProperty
    
    - (NSString*)someOtherMethod;
    @end
    
    ...
    

    The implementation remains the same, and works the same.

    You have the option of synthesizing your property in your implementation, and this allows you to remove the _myProperty instance variable declaration, and the generic property setter:

    @interface MyClass
    @property (nonatomic, retain) NSString* myProperty;
    - (NSString*)someOtherMethod;
    @end
    
    @implementation MyClass
    @synthesize myProperty = _myProperty; // setter and ivar are created automatically
    
    - (NSString*)myProperty {
        return [_myProperty stringByAppendingString:@" Tricky."];
    }
    
    - (NSString*)someOtherMethod {
        return [self myProperty];
    }
    

    Each of these examples are identical in how they operate, the property syntax merely shorthand that allows you to write less actual code.

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

Sidebar

Related Questions

Objective-C has directives like: @interface @implementation @end @protocol @property @synthesize I think of these
I know that you use @synthesize to create setter and getter methods, which makes
Is there any way to create a property like this C# property in Objective-C?
I'd like to create an internal auto-property: internal bool IP { get; protected internal
Is it possible to somehow create a custom @synthesize to generate custome getter, setters
I want to create a property grid (the one which is similar to the
I have a user control and I want to create a property of type
How can I create a custom property for my .Net assembly which would then
I am trying to create a custom property in a extended control, so that
I wanted to create a new property on a table in my model.. Basically

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.