How do I call +class methods in Objective C without referencing the class?

前端 未结 3 1481
面向向阳花
面向向阳花 2021-01-11 20:11

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

3条回答
  •  孤街浪徒
    2021-01-11 20:43

    This

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

    Should be

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

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

提交回复
热议问题