My idea is very similar to declare a variable of an interface type in java.
So for example,
header file 1:
@protocol Calculator
@end
I then define an @interface CalculatorImpl which implements the above Calculator protocol.
In header file 2:
@interface SomeViewController : UIViewController {
}
@property (weak, nonatomic) IBOutlet UITextField *txtResult;
@property (weak, nonatomic) Calculator* calculator;
@end
However, the xcode will flag an error at the calculator line
property with 'weak' attribute must be of object type
Is this usage of protocol disallowed by objective-c?
A
@protocolisn’t a type so you can’t use it for the type of a@property.What you probably want to do instead is this:
This declares a property with no restriction on its type, except that it conforms to the
Calculatorprotocol.