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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:08:12+00:00 2026-05-11T21:08:12+00:00

I have a series of policy objects which I thought would be convenient to

  • 0

I have a series of “policy” objects which I thought would be convenient to implement as class methods on a set of policy classes. I have specified a protocol for this, and created classes to conform to (just one shown below)

@protocol Counter   
+(NSInteger) countFor: (Model *)model;
@end

@interface CurrentListCounter : NSObject <Counter> 
+(NSInteger) countFor: (Model *)model;
@end

I then have an array of the classes that conform to this protocol (like CurrentListCounter does)

+(NSArray *) availableCounters {
return [[[NSArray alloc] initWithObjects: [CurrentListCounter class], [AllListsCounter class], nil] autorelease];
}

Notice how I am using the classes like objects (and this might be my problem – in Smalltalk classes are objects like everything else – I’m not sure if they are in Objective-C?)

My exact problem is when I want to call the method when I take one of the policy objects out of the array:

id<Counter> counter = [[MyModel availableCounters] objectAtIndex: self.index];
return [counter countFor: self];

I get a warning on the return statement – it says -countFor: not found in protocol (so its assuming its an instance method where I want to call a class method). However as the objects in my array are instances of class, they are now like instance methods (or conceptually they should be).

Is there a magic way to call class methods? Or is this just a bad idea and I should just create instances of my policy objects (and not use class methods)?

  • 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-11T21:08:12+00:00Added an answer on May 11, 2026 at 9:08 pm

    This

    id <Counter> counter = [[Model availableCounters] objectAtIndex:0];
    return ( [counter countFor: nil] );
    

    Should be

    Class <Counter> counter = [[Model availableCounters] objectAtIndex:0];
    return ( [counter countFor: nil] );
    

    In the first you have an instance that conforms to <Counter>. In the second you have a class that conforms to <Counter>. The compiler warning is correct because instances that conform to <Counter> don’t respond to countFor:, only classes do.

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

Sidebar

Related Questions

I have a series of datetime objects and would like to calculate the average
I have a series of PHP page, and I would like to use conditional
I have a series of <div class=clear-both></div> after a series of divs. I want
I have a series of grouped values that follow a specific format and would
I have a series of texfields, which I'd like to format as currency. Preferably,
I have a series of CodedUI test methods that make up a single test
I have about 15 series which I wish to scatter plot against a series
I have a series of performance tests I would like to show as a
I have a series of instance functions in a class. There is also a
I need to create a pdf file which will have series of images, where

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.