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

  • Home
  • SEARCH
  • 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 3480706
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:22:43+00:00 2026-05-18T10:22:43+00:00

Is it possible to handle a class with different instance variable types? Let’s say

  • 0

Is it possible to handle a class with different instance variable types? Let’s say I have a class that has two int instance variables, let’s call them:

@interface ClassA: NSObject {
  int x;
  int y;
}
@end

At the same time I want to extend it giving it the possibility to handle a different type on such instance variables like so:

@interface ClassB: ClassA {
  double x;
  double y;
}

Is this even possible?

  • 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-18T10:22:43+00:00Added an answer on May 18, 2026 at 10:22 am

    I’m pretty sure you can’t do that for two reasons:

    1. You can’t repeat instance variables (int x, double x).
    2. It’s pretty sketchy to inherit from one class, but then want to change the type of its instance variables.

    If you don’t want to make separate classes for these use-cases, perhaps an abstract superclass would work. If I more about what you’re trying to solve, I’d be able to be a bit more helpful in this area.

    What it seems like you really want is parametric polymorphism, which Objective-C does not support. Certain Cocoa classes, like the NSNumber family, use an abstract superclass with many concrete subclasses, presumably with different instance variable layouts (like you describe in your question). Then, logic is divided appropriately between the abstract and the specific. This is Cocoa’s Class Cluster design pattern, which is a sort of weakened, ad-hoc answer to the parametric polymorphism of languages like C++ and Haskell.

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

Sidebar

Related Questions

Is that possible to have a single PHP SOAP server which will handle requests
I am building an application that has to handle the parsing of several different
Given a handle of type HWND is it possible to confirm that the handle
Is it possible to have a draggable element with more than one handle? I
Lets say I have this class in foobar-shared.lib: class FooBar { std::string m_helloWorld; }
Possible Duplicate: StructureMap singleton usage (A class implementing two interface) I'm currently designing a
I have a class that reads a pop3 email server. I want to write
I currently have a connection class that handles all of my database connectivity. What
Is it possible to handle POSIX signals within the Java Virtual Machine? At least
I'm trying to handle this possible exploit and wondering what is the best way

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.