例如,我 subclass UIView,其中myString定义了一个名为的弱属性。@synthesize myString = _myString;语句有错误消息: Semantic Issue: @synthesize of 'weak' property is only allowed in ARC or GC mode。
MyUIView.h文件:
@interface MyUIView : UIView
@property (nonatomic, weak) NSString *myString;
@end
MyUIView.m文件:
#import "MyUIView.h"
@implementation MyUIView
@synthesize myString = _myString; // This statement causes an error whose message is Semantic Issue: @synthesize of 'weak' property is only allowed in ARC or GC mode
- (void)dealloc
{
[_myString release];
[super dealloc];
}
// Other methods
@end
然后我删除了这个@synthesize myString = _myString;语句还有另一个错误[_myString release];Semantic Issue: Use of undeclared identifier '_text'
如果不需要像myString上面那样合成或释放弱属性,我应该像这样重写代码:
MyUIView.h文件:
@interface MyUIView : UIView
@property (nonatomic, weak) NSString *myString;
@end
MyUIView.m文件:
#import "MyUIView.h"
@implementation MyUIView
- (void)dealloc
{
[super dealloc];
}
// Other methods
@end