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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T00:41:54+00:00 2026-05-12T00:41:54+00:00

I have following simple class: @interface Article: NSObject { NSString *title; } @property (copy,

  • 0

I have following simple class:

@interface Article: NSObject {
    NSString *title;
}
@property (copy, nonatomic) NSString *title;
@end

@implementation

- (void)setTitle:(NSString *)aString {
    if ((!title && !aString) || (title && aString && [title isEqualToString:aString])) return;
    dirty = YES;
    [title release];
    title = [aString copy];
}

- (NSString *)title {
    return title;
}

@end

In my application I have to do a lot of things like

Article *article= [objectsArray getObjectAtIndex:x];
NSString *title=article.title;
UILabel.text=title;
[title release];

I know I’m supposed to call retain when I get the property:

NSString *title=[article.title retain];

Maybe I am lazy to do a retain where I get the propery. Or If I need to do that tens of times all over the applicaiton.

Can I have getter to return a copy?

- (NSString *)title {
    return [title copy];
}
  • 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-12T00:41:55+00:00Added an answer on May 12, 2026 at 12:41 am

    There are some circumstances where I prefer to return a copy of the property for safety reasons. For example, if I’m writing a class that has a unique identifier property, then I’ll “return [[_uniqueID copy] autorelease]” so that there’s no chance that another class could do anything to the unique identifier. Other times I’ll just return the object itself, because it’s not a big deal if it’s externally manipulated.

    Also, with respect to these getter methods, they should not return objects with a +1 retain count (which is what you have going). If anything, they should return the object directly or return it with a +0 retain count (retain/copy + autorelease). It greatly simplifies your memory management to do it that way. If the external object needs to hold on to the returned object, then the external object should be responsible for retaining whatever it needs.

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

Sidebar

Ask A Question

Stats

  • Questions 137k
  • Answers 137k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This should do it: String txt = MyRichTextBox.Text File.WriteAllText(filepath, txt);… May 12, 2026 at 7:21 am
  • Editorial Team
    Editorial Team added an answer I do this using Getopt::Long together with Pod::Usage. (I got… May 12, 2026 at 7:21 am
  • Editorial Team
    Editorial Team added an answer What system are you on? In Unix/Linux you compile &… May 12, 2026 at 7:21 am

Related Questions

I did a quick google on implementing clone() in Java and found: http://www.javapractices.com/topic/TopicAction.do?Id=71 It
Lets say we have the following file and [folder] structure in a project with
I have written the following simple test in trying to learn Castle Windsor's Fluent
I am trying to use JAXB's introspection to marshall and unmashall some existing domain

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.