What's the difference between Self vs self ?
What's the difference between Self vs self ?
In Swift, the terms Self and self have distinct meanings and uses, which are crucial to understand for effective programming in the language.
selfself refers to the current instance of a class, struct, or enum.class Person {
var name: String
init(name: String) {
self.name = name // 'self' is used to distinguish the instance property from the initializer parameter
}
}
SelfSelf refers to the type of the current instance. It is often used in protocols and class hierarchies to ensure type integrity.Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.