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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:37:55+00:00 2026-05-27T07:37:55+00:00

Should setter generated with @synthesize be KVC compilant or not? I found statement that

  • 0

Should setter generated with @synthesize be KVC compilant or not? I found statement that getters and setters generated are KVC-compliant, shouldn’t it call one of this methods?

@interface testing : NSObject
@property (nonatomic, retain) NSString *phone;
@end

implementation:

@implementation testing
@synthesize phone;

- (id)init {
    self = [super init];
    return self;
}

// none of these is called with dot syntax, or setter setPhone
- (void)setValue:(id)value forKey:(NSString *)key
{
    NSLog(@"%@",key);
    [super setValue:value forKey:key];
}

-(void)setValue:(id)value forKeyPath:(NSString *)keyPath
{
    NSLog(@"%@",keyPath);
    [super setValue:value forKeyPath:keyPath];
}

@end

and test it with:

testing *t = [[testing alloc] init];
[t setPhone:@"55555555"];
  • 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-27T07:37:55+00:00Added an answer on May 27, 2026 at 7:37 am

    I think you’ve got it the wrong way round.. KVC compliant doesn’t mean that an accessor will call -setValue:forKey: Being KVC compliant means that calling -setValue:forKey: will call the accessor.

    Expanding a bit: KVC compliant only means ‘follows naming conventions‘. Why is this important? I can call my accessor methods anything i like. For a property ‘Foo’:

    - (void)weakSetFoo:(id)f;
    - (id)autoreleasedFoo;
    

    This is fine. But a mechanism like Bindings will try to set Foo by calling

    [ob setValue:newVal forKey:@"foo"];
    

    -setValue:forKey: will try to do the right thing and use the accessor method (if we wrote a setter method, it’s because we want it to be used, right?). But unless we named our setter method the standard -setFoo: there’s no way it will be found.

    So -weakSetFoo: is a setter method, but the property Foo isn’t KVC compliant.
    If i change the setter name to -setFoo: the property Foo is now KVC compliant.

    Synthesized accessor methods will by default be named correctly.

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

Sidebar

Related Questions

Should simple JavaBeans that have only simple getters and setters be unit tested?? What
Here is the problem statement: Calling a setter on the object should result in
Should you declare the getters/setters of the class inside the .h file and then
I have Hibernate Entities that look something like this (getters and setters left out):
Should I replace a simple setter public void setCategories(Set<String> categories) { this.categories = categories;
We're often told we should protect encapsulation by making getter and setter methods (properties
According to this answer here: Getter and Setter? The following function should work, however
I have a simple setter method for a property and null is not appropriate
It strikes me that Properties in C# should be use when trying to manipulate
I read some tutorials that say that a simple bean should be defined with

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.