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.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With