【发布时间】:2014-08-04 10:56:28
【问题描述】:
我想在.h 文件中创建一个不允许这些方法的单例(更多详细信息here):
+ (instancetype) alloc __attribute__((unavailable("alloc not available, call sharedInstance instead")));
- (instancetype) init __attribute__((unavailable("init not available, call sharedInstance instead")));
+ (instancetype) new __attribute__((unavailable("new not available, call sharedInstance instead")));
我可以在.m 文件的@interface MyClass () 部分重新定义它们以便能够在内部使用init 吗?
我正在寻找类似于在标题上创建 readonly 属性并在实现中将其重新定义为 readwrite 的内容(但对于 __attribute__)。
像这样:
// MyClass.h
@interface MyClass
@property (readonly) OtherClass *myThing;
@end
和
// MyClass.m
@interface MyClass ()
@property (readwrite) OtherClass *myThing;
@end
【问题讨论】:
标签: ios objective-c singleton clang