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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:50:11+00:00 2026-05-24T08:50:11+00:00

Icon is set as @property (nonatomic, retain) AHGridIcon *icon; Usually i just do: -(void)setIcon:(AHGridIcon

  • 0

Icon is set as @property (nonatomic, retain) AHGridIcon *icon;

Usually i just do:

-(void)setIcon:(AHGridIcon *)iconLocal {
icon = iconLocal;
} 

But i read a guide to getters setters and properties online which has lead me to believe that instead, this is right:

-(void)setIcon:(AHGridIcon *)iconLocal {
    if (iconLocal != self.icon)
    {
        NSLog(@"local: %@", iconLocal);
        NSLog(@"self.icon 1: %@", self.icon);
        [iconLocal retain];
        [icon release];
        icon = iconLocal;
        NSLog(@"self.icon 2: %@", self.icon);
    }
}

The problem is, the original icon is staying put, it’s not being replaced with the new icon. What am i doing wrong? Should i just revert to the usual way i do it?

  • 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-24T08:50:13+00:00Added an answer on May 24, 2026 at 8:50 am

    like I posted in my comment:

    the best way is to use @synthesize which will create a getter and a setter to with respect to the properties you wrote in your property (nonatomic, retain) => not threadsafe but fast getter and setter and a retaining (and also releasing) setter. If you dont need sophisticating stuff to do in your setter then you should not override the setter.

    .h:

    @property (nonatomic, retain) AHGridIcon *icon;
    

    .m:

    @implementation Something
    @synthesize icon;
    ...
    @end
    

    The code you posted in your setter is nearly the same as the compiler would produce when only using synthesize.

    Your usual way is not really nice because in your header is defined (in your property) that the setter is retaining but in your implementation you are overriding that correct setter which doesn’t retain. It is nearly the same as the compiler would produce with an (nonatomic, assign) property.

    But if you want to override your setter then it should look like the same as you wrote. For me it is working fine.

    1. first retaining the new object
    2. then releasing the old one
    3. then assigning the local pointer to your new object

    you can even omit your if but then it is really important that you first retain the new and then release the old objects (like you did – just want to mention that).

    For solving your problem with an overriten setter: Your setter looks ok in my eyes. Have you also overriten the getter? If yes then post it here (you use it by calling self.icon in your log-call).

    I’ve done a small test-program

    @synthesize str;
    
    - (void)setStr:(NSString *)localStr
    {
        if(str != localStr)
        {
            NSLog(@"old : %@", self.str);
            NSLog(@"new1: %@", localStr);
            [localStr retain];
            [str release];
            str = localStr;
    
            NSLog(@"new2: %@", self.str);
        }
    }
    

    and the output is fine:

    old : (null)
    new1: Hello
    new2: Hello
    
    old : Hello
    new1: World
    new2: World
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just found an icon set here: http://www.archetype-inc.com/yard/fundamentals/icons/ I've been looking for something like
I'm using the iconField property of the Flex Tree to dynamically set the icon
I'm going to set Window.Icon property by using ResourceDictionary like below: <Style TargetType={x:Type Window}>
I am trying to set the icon of the notifyicon control but everytime i
How do you set a border around a T-bootstrap icon? The css border property
I have try to set icon for my App in the xCode. In the
I'd like to know what's the way to actually set the icon of a
How do I set the executable icon for my C++ application in visual studio
I have a custom icon file (MyApp.icns) set up for my Cocoa App. How
How do I set a little icon next to the website title on tabs

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.