ios - What does an underscore "_" before a swift variable mean? -


here code:

var _selected: bool = false {     didset(selected) {         let animation = catransition()         animation.type = kcatransitionfade         animation.duration = 0.15         self.label.layer.addanimation(animation, forkey: "")         self.label.font = self.selected ? self.highlightedfont : self.font     } } 

why variable "_selected" instead of "selected"?

it's coding style shouldn't apply swift code.

developers mark things underscore indicate should private.

that said, there practical use underscore _. read more local , external parameter names methods.


so how avoid using _selected? right have 2 variables when have 1 need (selected).

removing _ require override member variable (how should done).

override var selected: bool {     didset {         println("hello, \(selected)")     } } 

additionally, table view cell have overridable method setselected(selected:animated) might worth exploring.


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -