Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a receiver in Objective C?

Tags:

objective-c

I'm confused as to what a 'receiver' is in Objective-C?

On the follwing site is says the following about what a receiver is: https://quizlet.com/104540068/objective-c-flash-cards/

"In Objective-C, you specify the object (known as the receiver of the method) and the message being sent to that object by enclosing the message expression in brackets."

I don't understand this. I'm very new to Objective C. Any help is appreciated. Thanks.

like image 734
Evan Sevy Avatar asked Mar 07 '23 03:03

Evan Sevy


1 Answers

In Objective-C, a message is sent to a receiver.

The message is the method you are calling. The receiver is the what the message is called on.

Example. Let's say you have an NSString:

NSString *str = @"Hello";

Now you want to get the length of the string. You send the length message to str. str is the receiver of the message:

NSInteger len = [str length];

Basically, the receiver is the part on the left inside the square brackets and the message is the part on the right in the square brackets.

like image 91
rmaddy Avatar answered Mar 18 '23 14:03

rmaddy