Is it a good way to access instance variable with self in a class?

class Person: NSObject {

var name = "John"


func greeting() {

let message = "Hello \(self.name)"

print(message)

}

}


take a look In greeting method of Persion class.

I'm using self.name that let me get clear "Im using instance variable now not local variable"

Is it a good way to access instance variable with self? If I use a lot.

I like it and personally, I wish the language required it in all cases. Then as you say, you can tell at a glance whether you're using a property or not. But the common practice seems to be *not* to use self. for property accesses for some reason, except where required e.g. within blocks.

While Apple doesn't (won't) have an official style guide, the two most-referenced unofficial style guides,


https://github.com/raywenderlich/swift-style-guide

https://github.com/github/swift-style-guide


both discourage use of "self" references unless required by the context (eg assigning an instance var or const from a liked-named parameter or, very specifically, when referencing an instance member within a closure, thus capturing the instance). By minimizing unneccessary self refs, those are much more visible, whereas they would likely would be buried in clutter if this was common practice.

There is actually a proposal for requiring this:


https://github.com/apple/swift-evolution/blob/master/proposals/0009-require-self-for-accessing-instance-members.md


So, it is in no way detrimental, at the moment it's purely a style thing, that may even be mandatory in the future.

Is it a good way to access instance variable with self in a class?
 
 
Q