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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:02:03+00:00 2026-06-01T20:02:03+00:00

this is my first post; this site has been an invaluable resource. I’m fairly

  • 0

this is my first post; this site has been an invaluable resource.

I’m fairly new to objective-c so please bear with.

So I have a base class with a few properties which I want “private” so I made them readonly. To be clear, I don’t want them mutable externally, but I DO wan’t to use the ‘set’ accessor within this class. So…

// .h file
@interface Vehicle
@property (nonatomic, readonly) int speed;
@end

Also I repeated the property declaration within a category interface block to make the accessors writable in this class

// .m file
//Private properties and methods
@interface Vehicle()
@property (nonatomic, readwrite) int speed;
@end

@implementation
@synthesize speed = _speed;
- (void) someMethod {
    [self setSpeed:10]; // Works fine
}

@end

But now if I inherit this class the derived class no longer has the set accessor method (setSpeed in my case). Do I need to synthesize again? Seems like that would defeat the purpose of inheritence. I know i can modify the instance variable directly (_speed = 10;) but would rather not. I’m sure there’s something wrong with my understanding. Thanks!

// Example
@interface Ship : Vehicle
@end

@implementation
- (void) someOtherMethod {
    [self setSpeed: 2]; // DOES NOT WORK, would like it to
}
@end
  • 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-01T20:02:05+00:00Added an answer on June 1, 2026 at 8:02 pm

    But now if I inherit this class the derived class no longer has the set accessor method (setSpeed in my case).

    Actually, it does have the set accessor, it’s just that the compiler doesn’t know about it. You have a choice:

    • put the class extension (the @interface Vehicle() .... @end bit in a separate header file that gets imported into the .m for Vehicle and its subclasses (or use a category)
    • redeclare the read/write property in a class extension for the subclass. To avoid a warning, use @dynamic speed in the subclass’s implementation.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first post, but I have been using this site for a
Well, this is my first post here and really enjoying the site. I have
This is my first post on Stack, so please bear with me if I
This is my first post. I know this topic has been discussed before in
This is my first post, but I've loved using this site as resource for
Ok this is my first post on Stack Overflow I have been reading for
This is my first post here. I have a problem. I need to take
The jqGrid has been kicking my butt (as well as others on this site).
My first post on this site with huge hope:: I am trying to understand
please go to www.espacioasir.com first and notice how the second article has been 'crushed'

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.