tags:

views:

108

answers:

3

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:)"?

+5  A: 
  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.
pgb
It's more accurate to say @selector(reload:) gives you the *name* of the method. You can get a pointer to a method, but that's quite different and doesn't work the same way.
Chuck
+4  A: 

@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 *).

Dietrich Epp
+3  A: 
  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 http://stackoverflow.com/questions/543161/explanation-of-cocoa-selector-usage

John M. P. Knox