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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:01:04+00:00 2026-05-20T14:01:04+00:00

In my implementation I have getters and setters like below. I want to use

  • 0

In my implementation I have getters and setters like below. I want to use properties and synthesize the getters and setters but have a few questions.

- (NSString *)title {
return title;
}

- (void)setTitle:(NSString *)value {
if(title != value) {
    [title release];
    title = [value retain];
}
}

If I was to convert that to a property, what attributes would I use? Am I right in thinking:

  • readwrite so both getters and setters are present
  • retain so that it increase the retain value of the value string so the object don’t lose it.

Am I right with the above?

One final thing. I have the method below …

- (void)setReleaseDate:(NSString *)value {
// YYYY-MM-DD HH:MM:SS +HHMM
if([releaseDate description] != value) {
    [releaseDate release];
    releaseDate = [[NSDate alloc] initWithString:value];
}
}

Am I right in thinking I still have to include that method because it contains code that the synthesized getter would not include?

Thanks.

  • 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-20T14:01:05+00:00Added an answer on May 20, 2026 at 2:01 pm

    For your title property, you can declare it in your class interface as follows:

    @property (nonatomic, retain) NSString* title;
    

    Which is the same as the following:

    @property (readwrite, nonatomic) NSString* title;
    

    readwrite is a default setting. Most of the time you will want setters for your properties, so for the times when you don’t you would use the non-default readonly to specify this.

    The nonatomic part basically means that the accessors will be faster, and is typically used. You can find out more information about this here: What does the property "Nonatomic" mean?.

    For your second question, you can implement your own accessors if you wish. If you do this then it kind of ‘overrides’ the accessor that would be generated by Objective-C. Remember that you have to keep to the naming conventions. So in your example, the “setReleaseDate:” method you’ve defined would be used for the setter method for the property “releaseDate” – which is completely correct! 🙂 The problem you have though is that you’re passing an *NSString** to set the date, which means that this method won’t override the default setter that would be used if you synthesized the property. You have to pass a value of the same type as the one you’re setting as the single argument, so for this case you would have to pass an *NSDate**.

    You must also ensure that if you provide your own implementation of an accessor that it does what is declared in the interface. I presume your releaseDate property should be declared as retain.

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

Sidebar

Related Questions

I have a few properties defined in my header file like so @property (assign)
I have this implementation with fusion table layers where I try to use the
For example: I have an implementation (say doSomething()) in Base class. I want all
What strategy should I use if I have an implementation of std::fstream with 32-bit
Consider the following scenario: (The following things have been omitted: Constructors, Getters and Setters,
I have a type that has index properties which I want to access via
If you synthesize a custom class, do getters and setters get created for it?
I don't know either my implementation have bugs or StringBuilder is going wrong. From
In my implementation I have this: /// <inheritdoc cref=IInterface{T} this[,]/> public T this[long row,
In relation to this question ( Efficient hashCode() implementation ) I have one more

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.