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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:57:30+00:00 2026-05-15T19:57:30+00:00

im searching for a convenient way of adding new arguments to multiple init-methods. its

  • 0

im searching for a convenient way of adding new arguments to multiple init-methods. its a little bit hard to discribe but my problem is the following:

I have a class witch implements various init-methods. f.e.

@interface Circle {
    CGPoint   center;
    float   radius;
}
- (id)initWithCenter:...radius:...;
- (id)initWithRect:...;  
- (id)initWithPoly:...;

Now f.e. i want to create a crosshair-class as a subclass. So i want to add maybe some lines as instance variables. So the problem is, every crosshair-object has to be initialized with some specific values, but of course the methods to initialize the circle wouldnt change. so i want every init-method from the superclass but add those specific arguments to each.

the direct way (in my unexperienced eyes) is to overwrite each method in witch i then call the according super-method and afterwards do my stuff. But this is very annoying if youve got 10 or more init methods and just want to add the same arguments to each. So im asking if theres a better approach to accomplish this? either with the ability to modify the superclass or without.

thanks a lot

  • 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-15T19:57:30+00:00Added an answer on May 15, 2026 at 7:57 pm

    Generally, you have one init* method variant that is the designated initializer. All other init* methods call through to that one and then do whatever customization they need. Subclassers would generally either add new init* variants that call [self init*] on the designated initializer as the first thing or subclassers would override the designated initializer (and and others as needed).

    However, this can rapidly get completely out of hand. For your Circle, it really seems like you just want:

    - (id)initWithCenter:...radius:...;
    

    And would then create a series of convenience factory methods to handle other types:

    + circleInRect:...;
    

    (I suspect your code is a contrived example or else I’d also point out the oddity that is a “crosshair” class as a subclass of a “circle” class. For something like that, I’d probably start with a Shape class, and then add Circle and Crosshair as a subclass of Shape. Obviously, the Sketch example is highly relevant.)

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

Sidebar

Related Questions

I am searching for a convenient but more important: reproducible way to measure the
Searching here I found that this question was already asked , but I think
searching around trying to find a way to add index on suffix of a
Searching for a while now, but haven't found a suitable answer to my problem.
Searching for a way to keep a registry of views and named adapters in
Searching since yesterday, but I only get adance method. I use spring with tomcat
Searching for an answer, some had noted the issue but no one resolved it.
Searching for a way to add this code, after the <head> (or some <link
Searching turns up a simple definition: data hiding. But, consider the following two examples:
Searching element of xml file using C# but getting following Error: Sequence contains no

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.