Refactoring old code, I want to change the following method:
- (id)initWithFrame:(CGRect)frame
{
// original logic
}
to:
- (id)initWithFrame:(CGRect)frame andDelegate:(id<myDelegateProtocol>)delegate
{
// original logic
if(delegate)
{
_delegate = delegate;
}
}
To ensure that no dependent code breaks, I update the original method to reference the old method, like so:
- (id)initWithFrame:(CGRect)frame
{
return [self initWithFrame:frame andDelegate:nil];
}
However, if anyone is still consuming that original method, I want Xcode to fire a warning (similar to when methods in iOS get deprecated). Ideally, something like:
- (id)initWithFrame:(CGRect)frame __warning__(@"This method has been replaced to ensure that you set the delegate. Please update your code.");
{
return [self initWithFrame:frame andDelegate:nil];
}
Note that these deprecations may happen before a new version iOS is released.
In the interface file, do this: