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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:12:01+00:00 2026-05-31T14:12:01+00:00

Within the last year, I’ve been working with other people on some Objective-C projects

  • 0

Within the last year, I’ve been working with other people on some Objective-C projects for the first time.

Occasionally (and increasingly) I’m seeing other people overriding getter/accessor methods, AND containing implementation code in this method! To me this is crazy town, as this is the whole point of having a setter…it also means that the property being set in the setter will just be overridden in the getter, and therefor pointless.

Are these people behaving badly, or am I the one who’s missing something? Is there EVER a need to override a synthesized property’s getter method?

Example:

@synthesize width;

- (CGFloat)width {
  NSNumber *userWidth = [[NSUserDefaults standardUserDefaults] objectForKey:@"USER_WIDTH"];

  if (userWidth != nil) 
  {
    width = [NSNumber floatValue];
  }     

  //Shouldn't the above lines be done in the SETTER? I have SET the property!
  //Why would I ever need to write anything BUT the below line??       
  return width;
}

- (void)setWidth:(CGFloat)newWidth {
  //THIS is where you do the the setting!
  width = newWidth;
}

UPDATE:

Ok width is a bad example. Too many people are getting caught up on the semantics of “what the variable is” and “don’t include get in objective-c accessors”. So I’ve updated the above example to ignore the irrelevant semantics, and concentrate on the concept. The concept being…is there any example when you’d want to override the GETTER (not setter, getter only. I override the setter many times, this question is about the getter)?

Returning another property such as layer (as mentioned below) is a genuine example. But more specifically is there ever a need to SET the property in a GETTER? This is some of the weirdness that I’m seeing, so i’ve updated the getter above to pull a value from the NSUserDefaults to aid my point…

  • 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-31T14:12:03+00:00Added an answer on May 31, 2026 at 2:12 pm

    The first issue is you don’t want to use getWidth. The pattern in objC is name and setName. Do not use getName. It messes up binding and KVO.

    Also, if it’s just setting/getting the iVar, there’s no reason to override. If you’re doing extra processing/validation then it may be Ok to override.

    EDIT:

    You should also try to avoid setting data and doing heavy processing in the getter. A getter is supposed to encapsulate some state and return data. The expectation is that it’s very light weight. Heavy processing and/or modifications should be done in methods or setters. For example, folks set debug watches on getters and don’t expect heavy processing and modification of state.

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

Sidebar

Related Questions

For the past year I've been working on some legacy code that was written
Within the last year I have become addicted to subversion. I am an only
I'm using Drools (for the first time) to express some rules and it has
This has inexplicably started happening within the last 6 months or so. This same
We need to make sure only results within the last 30 days are returned
I am attempting to populate a list of records within the last X seconds
How do I get the div from within this (the last) list item? Currently
How would I get the last occurrence of an NSString within another NSString? For
I need to find the last index of a string (e.g. - ) within
I need to be able to find the last occurrance of a number within

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.