Reputation: 2636
setting any method to deprecated is as easy. See How do I flag a method as deprecated in Objective-C 2.0?
BUT: How can I set a method deprecated only for public use?
Upvotes: 4
Views: 338
Reputation: 8012
Another choice is to add a macro that is defined in your build flags and not defined in theirs.
// Add -DBUILDING_MYPROJECT=1 to your own build flags.
#if BUILDING_MYPROJECT
# define MYPROJECT_DEPRECATED_API
#else
# define MYPROJECT_DEPRECATED_API DEPRECATED_ATTRIBUTE
#endif
...
-(void) method MYPROJECT_DEPRECATED_API; // deprecated for clients, not deprecated for you
Upvotes: 3
Reputation: 50129
you could define it in two headers.. in two different categories.
dont define it on the class itself.
that way you separate them
e.g. you have:
T has a deprecated property. But internally you want to use it
so to 'clients' you expose it as deprecated in a Category while the private m file just declares it itself not-deprecated
main file : (client)
#import <Foundation/Foundation.h>
#import "T+Public.h"
int main(int argc, const char * argv[])
{
@autoreleasepool {
T *t = [[T alloc] init];
NSLog(@"%@", t.deprecated);
}
return 0;
}
T.h
#import <Foundation/Foundation.h>
@interface T : NSObject
@end
and T Public
#import "T.h"
@interface T (Public)
@property(nonatomic, readonly, copy) NSString *deprecated DEPRECATED_ATTRIBUTE;
@end
and Finally T.m that DOESNT import the public interface
#import "T.h"
@interface T ()
@property(nonatomic, copy) NSString *deprecated;
@end
@implementation T
- (id)init {
self = [super init];
self.deprecated = @"LALA";
NSLog(@"%@", self.deprecated); //NOT DEPRECATED!
return self;
}
@end
Upvotes: 1