Self or self in Swift Code?
That capital letter makes a real difference
3 min readMay 4, 2022
Difficulty: Beginner | Easy | Normal | Challenging
Prerequisites:
No specific prerequisites are required for this article
Video:
Some find a video to be more to their liking, so here is the video support for this article
What is self?
self
(with a lowercase s) is a property of an instance that holds the instance itself. This means `self` can refer to any current object.
self
is a common sight in much Swift code. Yes, since Swift 5.3 we do not have to explicitly declare self on a value type.
What? What is Self?
self
(with a lowercase s) is an object. It can represent a struct
, class
or property.
Self
(with an uppercase S) is a type. This means that Self
can mean any current type.