Questions tagged [self]

A keyword used in instance methods to refer to the object on which they are working.

In many object-oriented programming languages, self (also called this or Me) is a keyword that is used in instance methods to refer to the object on which they are working. Languages like and others such as , and use self. uses self or super; and languages which derive in style from it (such as , , and ) generally use this. Visual Basic uses Me.

Invoking a method on the self searches for the method implementation of the method in the usual manner, starting in the dispatch table of the receiving object’s class.

Example:

[self startThread];
self.hostReach = YES;
BOOL value = self.hostReach;

Here, self is a variable name that can be used in any number of ways, even assigned a new value.

Inside an instance method, self refers to the instance; inside a class method, self refers to the class object.

1538 questions
-1
votes
2 answers

Python interpreter couldn't find the class variable

I am trying to create a distributed hash table. There is a thread. But the run function in the thread cant find the sock variable which I am initializing in the constructor. Here is the code - from socket import * from threading import * class…
odbhut.shei.chhele
  • 5,834
  • 16
  • 69
  • 109
-1
votes
1 answer

What is "self" and how was the "view" property used?

In this: -(IBAction)buttonClick: (id)sender { UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Fo Sho?" delegate:self …
Devoted
  • 177,705
  • 43
  • 90
  • 110
-1
votes
2 answers

Understanding Classes and Methods in Python 3

Alright, after viewing a lot of tutorial videos about classes i'm still having trouble understanding them for this assignment i have to do. I need to write a program that essentially does high card, which means I need 2 cards to face off and one be…
user2305960
  • 37
  • 1
  • 2
  • 4
-1
votes
2 answers

What's the difference between omitting `self` in method definition or not?

I know self is the receiver of the method calling. But I do not know if there is not self in method definition. code example: class One def kk "kk" end def self.kkk "kkk" end end puts One.new.kk puts One.kkk Why do I need to use…
stardiviner
  • 1,090
  • 1
  • 22
  • 33
-1
votes
2 answers

What is the main use of self?

I am working on a ARC based project. I am just wondering what is the main use of self ? I am having an array as follows @property(strong,nonatomic)NSMutable *dataArray; I am initializing the array as follows -(void)viewDidLoad{ …
Raj
  • 1,119
  • 1
  • 15
  • 32
-1
votes
1 answer

Self and proc.call parameter

I know there are already a lot of questions about self, but I just wanted to make sure I've understood it. def buttonPressed @action.call(self) end In this code, self refers to @action (because @action is the receiver of the call method). Is…
-1
votes
1 answer

IOS: When declaring properties in a .h what's the difference between self.var and just var?

Possible Duplicate: Objective-C - When to use 'self' I needed a variable to be passed from one view to another so I made a property called StringC in the .h and accessed it using self.StringC (that part worked). I also need some arrays that are…
user1515993
  • 69
  • 1
  • 7
-1
votes
1 answer

Accessing instance without self

I have the following code. In the dataReceived method, I am trying to access table, but I get an error. It works if I use self and do all of that, but I don't want to use self. Using self would not work for my purpose. How can I still gain access to…
Alec
  • 919
  • 2
  • 10
  • 25
-2
votes
1 answer

Why is a function without self argument not visible to other functions in that class?

In Python, when I'm defining a function inside a class, I can include self as one of the arguments to access the member variables of that class, and I can also choose not include self as the argument if I don't need to access its member variables.…
-2
votes
1 answer

How do you get input to assign the values of structs from user input while in another struct's impl?

I am making a number guessing game, where the player who guesses the closest wins. struct Player { name: String, balance: i32, betamount: i32, guess: i32 } struct Game { p1: Player, p2: Player, random_card: i32 } impl…
Ari Rosen
  • 13
  • 1
-2
votes
1 answer

Python: OOP Tutorial 1: Classes and instances: How to use self?

I try to learn about classes in Python. Currently, I use the the tutorial from Corey Schafer. Here is what he wrote: class Employee: def __init__(self, first, last, pay): self.first = first self.last = last self.pay =…
BGandul
  • 17
  • 5
-2
votes
1 answer

Relation emp-super

creat table supervisors ( person char(20) not null, supervisor char(20) not null, constraint supervisor-pk primary kye(supervisor), ); instr into supervisors value('Bob','Alice'); instr into supervisors value('Mary','Susan'); instr into…
-2
votes
1 answer

Class with two methods,can not be defined Python

#Hello i made this program but something seems to not be ok. Firstly i made it with one method "next_question" but i have to do it with two. So i made calc_vathmo,when i did this i found some errors and i fixed some of them. I tried with the static…
Tsakhs
  • 1
-2
votes
1 answer

What is the purpose of varB = self(varA) in a Python class?

I am debugging a Python code and see this code pattern in one of the classes: def someOtherFunction (x): return x**2 class baseX(): pass class baseY(): pass class newBase (baseX, baseY): def __init__ (self, **kwargs): …
-2
votes
1 answer

Python classes - Call multiple class methods in one line

I am trying to combine some class methods or apply init value on itself without success. class numOper: def __init__(self, x): self.x = x def multiply(self, x): self.x *= x def add(self, x): self.x +=…