Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are curly braces required in @interface declarations in Objective-c?

The following code compiles:

@interface MyClass : ParentClass // missing {
// missing }
@property (nonatomic, copy) NSString *myString;
@end

I'm wondering if the curly braces in @interface declarations are actually necessary.

like image 241
SundayMonday Avatar asked Sep 06 '11 22:09

SundayMonday


People also ask

Do ELSE statements need curly braces?

For Java, curly braces are optional for if-else statements. As Jared stated, only the next statement will be executed when curly braces are omitted. Generally the braces help with organization and readability of the code, so they commonly will be used.

What is the rule of curly braces in C program?

In programming, curly braces (the { and } characters) are used in a variety of ways. In C/C++, they are used to signify the start and end of a series of statements. In the following expression, everything between the { and } are executed if the variable mouseDOWNinText is true. See event loop.

Why do we use {} in Python?

In languages like C curly braces ( {} ) are used to create program blocks used in flow control. In Python, curly braces are used to define a data structure called a dictionary (a key/value mapping), while white space indentation is used to define program blocks.

Why do we use block of statements with braces in C++?

The curly brackets are there to allow easy parallel code structure. That is, suppose you wanted to do the same operation again. Without the curly brackets, you would not be able to cut and paste that code block, perhaps with modifications. It is because you can only declare serial_num once at the top of any scope.


Video Answer


1 Answers

No, the { } section isn’t necessary; your code will compile fine without it. It’s the area where you declare instance variables, and if you’re not doing that, you’re free to leave it out. You don’t even actually need to declare ivars for your properties—the compiler’s smart enough to add them where they’re needed.

like image 133
Noah Witherspoon Avatar answered Sep 28 '22 11:09

Noah Witherspoon