Reputation: 687
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.
Upvotes: 4
Views: 699
Reputation: 318824
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.
Upvotes: 8