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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:42:42+00:00 2026-05-22T22:42:42+00:00

I read somewhere that with NSString in an object, one has to use copy

  • 0

I read somewhere that with NSString in an object, one has to use copy instead of retain. Can someone explain if this is correct and why?

For example I have the following declaration for my singleton:

#import <foundation/Foundation.h>
@class FaxRecipient;

@interface MyManager : NSObject {
    NSString *subject;
    NSString *reference;
    NSString *coverSheet;
    FaxRecipient *faxRecipient;

}

@property (nonatomic, retain) NSString *test1;
@property (nonatomic, retain) NSString *test2;
@property (nonatomic, retain) NSString *test3;
@property (nonatomic,retain) FaxRecipient *faxRecipient;



+ (id)sharedManager;

@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-22T22:42:42+00:00Added an answer on May 22, 2026 at 10:42 pm

    I think “has to” in the sense of must is a little strong. You can use either copy or retain, but you should generally use copy for your NSString* properties because:

    1. You usually don’t want a string property to change under your nose;
    2. NSMutableString is a subclass of NSString, so it’s entirely possible that someone might set your NSString* property to point to a mutable string, thus creating the potential for the string to be changed while you’re using it;
    3. For immutable classes like NSString, copy operations end up just retaining the original object anyway.

    Considering those three points, it’s hard to think of a good reason to use retain instead of copy for your NSString properties.

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

Sidebar

Related Questions

I've read somewhere that you can snap the object after it has been moved,
I read somewhere that one should never use error conditions as normal program flow.
I read somewhere that you can stop Magento from requiring two product descriptions... this
I think I've read somewhere that this is possible. Use case I want to
I read somewhere that snprintf is faster than ostringstream. Has anyone has any experiences
I think I read somewhere that some modules only have object oriented interfaces (
I read somewhere that it is disastrous to use free to get rid of
I read somewhere that synchronized(this) should be avoided for various reasons . Yet some
I read somewhere that one of few weaknesses in data binding model is that
I read somewhere that ruby threads/fibre block the IO even with 1.9. Is this

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.