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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:18:56+00:00 2026-05-24T10:18:56+00:00

I have two properties NSString, both of which I have synthesized and are readonly

  • 0

I have two properties NSString, both of which I have synthesized and are readonly and so I cannot use the property method self. but I though both the passed string most be retained. So, I added retain to retain the properties. But I feel, I will have leaks here since the passed objects are have increased their retain count. But will my properties retain these string without sending message retain.

-(void)setValue:(NSString *)passedString1 second:(NSString *)passedString2{
     myString = [passedString1 retain];
     hisString = [passedString2 retain];
}

Lets say I have property for array(variable) declared as NSArray and I pass NSDictionary as argument this way;

NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@"text", @"This is some text", nil];
[self setValueForArray:dict];

-(void)setValueForArray:(NSDictionary*)passedDict{
 NSArray *someArray = [NSArray arrayWithObject:passedDict];
 if(array!=someArray){
 [array release];
 array = someArray; //I dont think I should retain this property here since it is retained by someArray
 }
}

Is this approach correct for NSDictionary and NSArray types.

  • 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-24T10:18:57+00:00Added an answer on May 24, 2026 at 10:18 am

    Use copy for Strings and release the previous object:

    -(void)setValue:(NSString *)passedString1 second:(NSString *)passedString2
    {
         if (myString != passedString1)
         {
             [myString release]; 
             myString = [passedString1 copy];
         }
    
         if (hisString != passedString2)
         {
             [hisString release];
             hisString = [passedString2 copy];
         }
    }
    

    If you need to release the Strings that were passed in as parameters, do it in the calling method after calling setValue:

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

Sidebar

Related Questions

I have two arrays of custom objects. Both have properties of NSString *name. I
I have a Person Object which has two NSString properties; firstName and lastName .
I've defined two properties with corresponding ivars and synthesized them: @property (nonatomic,copy) NSString* title;
I've the problem: I have to serialize class to XML file. But two properties
I have two properties files, but something is wrong, inputStream is always null? <application>
I have two internal properties that use lazy-loading of backing fields, and are used
Say I have two properties defined as such: @property (nonatomic, strong) UITableView *parentTableView; @property
I want to create a class which will have two properties, e.g. key &
I have a list of objects that have two int properties. The list is
I have a uiviewcontroller with two properties: trackName and playerObject. PlayerObject also has a

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.