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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:18:32+00:00 2026-06-08T23:18:32+00:00

I need to, for example, execute NSLog(@Executed.) every time my synthesized getter or setter

  • 0

I need to, for example, execute NSLog(@"Executed.") every time my synthesized getter or setter gets called. I see 2 ways to do that:

  1. Find some snippets that work probably like synthesized ones. This thread may help in that.
  2. Use KVO: add some observer which will do the work.

All of them doesn’t looks satisfactory clean for me.
So, subj.

UPDAE: Thank for answers, but directly overriding isn’t a solution:
we loose synthesized code. If we “copy paste” “right” synthesized code from somewhere (even from apple forum where apple engineer gives us code) we should check that it isn’t changed after next compiler release.

  • 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-06-08T23:18:34+00:00Added an answer on June 8, 2026 at 11:18 pm

    You can write an additional property, with your custom getter and setter, that does your own thing, and then accesses the @synthesized ones, like so:

    Foo.h:

    @interface Foo : NSObject
    {
        int bar;
    }
    
    @property int bar;
    @property int bar2;
    
    
    @end
    

    Foo.m:

    #import "Foo.h"
    
    @implementation Foo
    
    @synthesize bar;
    
    - (int) bar2
    {
        NSLog(@"getter");
        return self.bar;
    }
    
    - (void) setBar2:(int)newBar
    {
        NSLog(@"setter");
        self.bar = newBar;
    }
    @end
    

    and then your code:

    Foo *foo = [[Foo alloc] init];
    foo.bar2 = 1;
    foo.bar2 += 2;
    [foo release];
    

    So you would use “bar2” as your property, but you get all the niceties out of the @synthesized bar. Anything in bar would be set/get in a thread safe manner, and any additional logic in bar2 would not (which may not matter to you)

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

Sidebar

Related Questions

I need to execute an action after a specific amount of time (for example
I need to execute a SQL Query between two databases. Example: SELECT * from
I need to execute a program in Windows 7 that uses a file as
I need execute 2 select in SQLAlchemy. For example: select1 = Session.query(col1, col2, col3,
I need to execute a command per line of some file. For example: file1.txt
Actually I need to know how this line is getting executed. Example: Browser(InternetExplorer).Page(Stackoverflow).WebElement(textbox).set user
I need to execute a function every tot hours, right now I'm doing it
I need to execute some dynamically generated code in Python and ensure that this
I need to create an method invoker that any thread (Thread B for example
I need to execute a query at given time. I read about mysql events,

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.