开发者

Is this property assignment for iOS correct?

开发者 https://www.devze.com 2023-01-27 04:10 出处:网络
I\'ve seen that you should assign a property this way: - (void)viewDidLoad { NSDateFormatter *tempFormatter = [[NSDateFormatter alloc] init];

I've seen that you should assign a property this way:

- (void)viewDidLoad {

    NSDateFormatter *tempFormatter = [[NSDateFormatter alloc] init];
    self.dateFormatter = tempFormatter;
    [tempFormatter release];
}

...

- (void)dealloc {

    [dateFomatter release];
    [super relase];
}

Where dateFormatter is defined like开发者_如何学Go this

// Header
@property (nonatomic, retain) NSDateFormatter *dateFormatter;

// Implementation
@synthesize dateFomatter;

This way I avoid a double assignment.


Yes, this is ok. It uses the retain from the synthesized setter.

0

精彩评论

暂无评论...
验证码 换一张
取 消