Swift – weak self in Didset

I rarely see people using [weak self] in didSet. Is there a reason?

I tried to use [weak self] in the didSet of the variable:

var data: Dictionary! {// [1]
didSet {[2]
self?.layoutSubviews()
}
}

Either [weak self] is in [1] or [ 2], I still get the error: Use of unresolved identifier is weak

Why is this? Is it illegal to use [weak self] for didSet?

Greetings,

didSet is not a closure, you can’t use closure syntax .

There is no reason to use weak self there. The didSet handler does not create the ownership cycle in the same way as the method does not create the ownership cycle.

I rarely see people using [weak self] in didSet. Is there a reason?

I tried to use [weak self] in the didSet of the variable:

var data: Dictionary! {// [1]
didSet {[2]
self?.layoutSubviews()
}
}

Either [weak self] is in [1] or [ 2], I still get the error: Use of unresolved identifier is weak

Why is this? Is it illegal to use [weak self] for didSet?

Greetings,

didSet is not a closure, you cannot use closure syntax.

No The reason is to use weak self there. The didSet handler does not create the ownership cycle in the same way that the method does not create the ownership cycle.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 4174 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.