self keyword swift simple example – what is use ?

By | August 4, 2016

Use of self keyword swift simple example

One of the use of “self” keyword in swift is when you want refer a property within structure, class or enum. We can understand by the following example:

when we call function and within its definition if there’s written x+2 then it will refer to the x passed in function call whereas if inside definition of the function we’ve written self.x then it refers to the x that is one of the structure property.