InterviewSolution
Saved Bookmarks
| 1. |
Show the use of "self" in a method using an example. |
|
Answer» In Swift, the self property of an instance is a special property that holds the instance itself. In most cases, self appears in a class, structure, or ENUMERATION's initializer or method. The most common use of self is in initializers when you are likely to WANT parameter names that match your TYPE's property names, such as this: struct student { var myName: STRING var myFriend: String init(myName: String, myFriend: String) { print("\(name) is being ENROLLED in class...") self.myName = myName self.myFriend = myFriend }} |
|