lucius
lucius

Reputation: 2427

Need help in understanding objective c code

I need some help in understanding the following code:

  1. What is the meaning of '@' in @"Reload"

    button = MakeTestButton(&button_rect, @"Reload", content); [button setTarget:web_view]; [button setAction:@selector(reload:)];

  2. Where I can find the definition of "@selector(reload:)"?

Upvotes: 0

Views: 200

Answers (3)

Dietrich Epp
Dietrich Epp

Reputation: 213688

@selector is a built in primitive in the language. Think of @selector(reload:) as “the name of the method reload:”. It returns a SEL, which you can then pass to a function and later use it to call the method reload:. In the context of your code, when you click the button, the button will call [web_view reload:self].

In @"Reload", the @ means that it's an NSString instance instead of a char const *.

Upvotes: 4

John M. P. Knox
John M. P. Knox

Reputation: 713

  1. The @ sign indicates to the compiler that the string is an NSString instead of a standard "C" string. This is a shortcut for creating NSString objects.

  2. See Explanation of Cocoa @selector usage

Upvotes: 4

pgb
pgb

Reputation: 25001

  1. String constants are declared as @"some text" in objective-c. This creates an instance of NSString.
  2. I recommend you read Apple's documentation on selectors. Basically, @selector(reload:) will get a pointer to the method that will be called when an objects receives a reload: message.

Upvotes: 5

Related Questions