Domanda

I'm reading a code example on Github and I see something I would to understand how it works.

the code is something like:

- (void)viewDidLoad
{
    [super viewDidLoad];

    {
        self.formatter = [[NSDateFormatter alloc] init];
        [self.formatter setDateFormat:[NSDateFormatter dateFormatFromTemplate:@"yyyyMMMd" options:0 locale:[NSLocale currentLocale]]];
    }

}

what does it mean? is it something related to the async execution of code portion? does anybody enlighten me?

È stato utile?

Soluzione

You said brackets. Are you talking about curly braces instead? "{" and "}".

Curly braces define a local scope. It can be used simply for code readability, or you can also use it to limit the scope of local variables:

- (void)viewDidLoad
{
  [super viewDidLoad];
  {
    //local variables inside these braces are only defined inside this set of braces
    NSString *scratchString;
    int count = 1;
    scratchString = @"foo";
  }

  {
    //The string scratchString below is a different local variable than
    //The one defined above.
    NSString *scratchString;
    int count = 5;
    scratchString = @"bar";
  }
}

Altri suggerimenti

The [] is how objective C communicates through messages. It is just a little bit slower then if it was a function.

Those brackets are Objective C method call syntax.

The basic syntax of an instance method call is

[target_object message_name];

if the message takes a parameter:

[target_object message_name: parameter];

I suggest reading a book on the Objective C language.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top