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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:07:25+00:00 2026-05-26T13:07:25+00:00

Say I have two classes: @interface Rectangle: NSObject { int width; int height; }

  • 0

Say I have two classes:

@interface Rectangle: NSObject {
    int width;
    int height;
}

// Methods here...

@end

@interface Square: Rectangle

- (void)initWithLength:(int) length;

@end

Square inherits from Rectangle. Now, if I have a method that takes a Rectangle in another class, say, - (void)drawShape:(Rectangle *) rectangle, can I pass a Square object to it? Should I be using id? What is the best way to dynamically type inherited classes?

Also: This is just an example. My classes are much more complicated than this. For instance, categories would not apply for my actual problem. And if I were using an abstract class above Rectangle, Shape for example, would that change the answer?

  • 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-26T13:07:26+00:00Added an answer on May 26, 2026 at 1:07 pm

    If you have a known base class then you should use that. id is useful if you are doing duck typing, but compile time checking is always a good measure against bugs.

    id is generally used in concert with protocols. Let’s say you have one called MyProtocol. Then you could type a var as id < MyProtocol >. This will allow the compiler to statically verify your code.

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

Sidebar

Related Questions

Let's say we have these two classes: public class Base { public static int
Say I have two independent classes: class Foo { int bar; } class Baz
Say you have these two classes. public class Author { public int ID {get;
Say I have two classes and have a requirement that the primary key property
Say you have two classes, A and B. Is it possible to instantiate both
Say I have two classes created work and workItem. CWorker *work = new CWorker();
Say I have two classes, and neither of them are GUI components. Class A
Let's say we have two classes, Foo and Foo Sub, each in a different
Let's say I have two classes, A and B, where B is a child
Say I have two separate classes, A and B. I also have Repository class

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.