Swift - What is 'self'?

preview_player
Показать описание
Self is a concept that confused me a bit as a beginner as I saw it all over my code base but never really understood WHY I had to use it and what it meant. In this video I hope to clear that up for you.

*** This video is an excerpt from my beginner course called iOS Dev Launchpad. If you're interested in seeing the curriculum for the full course to get started learning iOS Development and Swift, here's the link:

If you like my teaching style, I've started releasing my own courses:

Twitter:

Link to my book - How I Became an iOS Developer:

Check out my podcast, iOS Dev Discussions:

Book and learning recommendations that help out the channel if you decide to purchase (Affiliate Links):

Ray Wenderlich Books:

Ray Wenderlich Videos:

Mark Moeykens SwiftUI Views & Animations Mastery:

Donny Wals - Combine Framework:

Paul Hudson's Hacking With Swift:

Learn Advanced Swift Here:

Links to my iOS Dev Setup & iOS Dev Book Recommendations

#swift #softwaredeveloper #iosdeveloper
Рекомендации по теме
Комментарии
Автор

If you enjoy my teaching/presentation style I've started creating courses at seanallen.teachable.com. You can watch the first few videos of all my courses for free to get a feel for them.

seanallen
Автор

This is a deep title and made me reflect on things. What is "self"? Thanks for breaking down what self is in Swift.

jcubedapps
Автор

Thank you for making so simple to understand. I was searching all over the web and I couldn’t understand until I saw your video.

rickmarz
Автор

Keep it up Sean! I love your content. I started learning Swift about 2 months ago. Your videos help get me through the workday and I follow along when I get home. Thanks!!!

mac
Автор

oh man Sean! usage of "self" confused me for days despite knowing disambiguation between parameter and property...yadda yadda..but thanks for making this tutorial...i know lot of new developers will love you for this because finding a clear explanation is still very difficult.

stillwrinkled
Автор

Your teaching way is the best for learning, I have ever experienced.

gmostafaali
Автор

I see what you did there in the beginning haha! so funny lol!

shadieossei
Автор

THANK YOU!! I've been so hung up on this and going a bit nuts.

leahleavitt
Автор

Objective-C was fun because we had self and the id. The id operates on the pleasure principle (Freud, 1920) which is the idea that every wishful impulse should be satisfied immediately, regardless of the consequences. When the id achieves its demands, we experience pleasure when it is denied we experience ‘unpleasure’ or tension.

swiftcoding
Автор

this and self in php
$this indicate object context for non static data and self will be used for referring a static member of a class.

Faisalx
Автор

Hi! Please do a video on how to pass functions/types as parameters/outputs in functions

ricolamoretti
Автор

I remember using self without understanding it :) good old noobie days

BekaDemuradze
Автор

One more meaning of "self" is like "type", for example JsonDecoder().decode(DataModel.self, from: data)

zhaoyangli
Автор

therres also Self now (capital S) which referring to static owner name.

MrDonhekel
Автор

is it similar to "this" keyword in java?

chetanjeevsinghbains
Автор

Summary
- An introduction to the concept of "self" in Swift programming.
- "Self" refers to the current instance of a class or object.
- It is used to access and modify properties and methods within the class.
- "Self" is used in initializers to refer to the instance being initialized.
- It is also used to set delegates and data sources in table views.

Highlights
- 💡"Self" is a shorthand way of referring to the current instance of a class or object.
- 💡It is used to access and modify properties and methods within the class.
- 💡In initializers, "self" is used to set properties of the current instance.
- 💡"Self" is used to associate table view delegates and data sources with the current class.
- 💡Understanding the concept of "self" is important in Swift programming.

phongho.design
Автор

Now I know "what" is self, but I think more importantly I want to know "why" do we need to use self. For the background color, you said that using self.backgroundColor will distinguish between the variable that we want to change with the passed in value. That's fine, but most other times, that explanation doesn't fit. For example setTitle(title) does not have similar looking variables so why do we still need to use self? Fundamentally what is the difference between self.setTitle() and just plain setTitle()? Under what situation do we need to use self?

Kuraudo_VII
Автор

With full respect, for the first time, I didn't satisfy with your explanation. Especially the connection to delegates. why should we pass an instance of a complete class to a simple delegate?

TheAhmadReza
Автор

So Sean, shall we say that self is similar to "this" in Java?

TheBorpol
Автор

self.fromSean = "I'll Get Heart"

pratikgupta