For example, I subclass UIView
, in which a weak property called myString
is defined. There is an error message for @synthesize myString = _myString;
statement: Semantic Issue: @synthesize of 'weak' property is only allowed in ARC or GC mode
.
The MyUIView.h
file:
@interface MyUIView : UIView
@property (nonatomic, weak) NSString *myString;
@end
The MyUIView.m
file:
#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
Then I removed the @synthesize myString = _myString;
and there goes another error for this statement [_myString release];
as Semantic Issue: Use of undeclared identifier '_text'
If it's not necessary to synthesize nor release a weak property like myString
above, should I re-write the code like this:
The MyUIView.h
file:
@interface MyUIView : UIView
@property (nonatomic, weak) NSString *myString;
@end
The MyUIView.m
file:
#import "MyUIView.h"
@implementation MyUIView
- (void)dealloc
{
[super dealloc];
}
// Other methods
@end