Hey,
I am new to programming I wanted to know why is it always [self method];? I mean why is it that way could someone explain me why is it self and what is going on in the background? sorry if it is a stupid question
thanks,
TC
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Basically, what
selfrefers to is the object that you’re currently in the context of.[self somemethod]means that you’re invoking a method namedsomemethodin the class thatselfwas initialized as.For example, if you were to do something like this:
You’d be invoking
someMethodon theFooinstance.But if you’re working inside of the class
Foo, self serves as an explicit reference to the current object. In this case, you’d simply use[self someMethod]to invokesomeMethod.Does that help?