Varieties of @interface declarations, some with parentheses

I noticed a lot of declarations @interfacefor Objective-c classes. I would like to understand why developers announce in the @interfacefollowing ways:

// in the .h file
@interface MyClass : NSObject
// ...
@end

// in the .m file (what the purpose of the parens?)
@interface MyClass ()
// more property declarations which seem like they can go in the .h file
@end

// again in the .m file (what the purpose of private?)
@interface MyClass (Private)
// some method declarations
@end
+5
source share
3 answers

This is the normal normal class interface , inheriting from NSObject, where you declare ivars, properties, and methods

// in the .h file
@interface MyClass : NSObject
// ...
@end

categories, . ( , ). (, @interface MyClass (Private)), ​​ @implementation MyClass (Private), ( ) , . , ivars , (named) .

// in the .m file (what the purpose of the parens?)
@interface MyClass ()
// more property declarations which seem like they can go in the .h file
@end

// again in the .m file (what the purpose of private?)
@interface MyClass (Private)
// some method declarations
@end
+5
+2

What happens in the file .mis private. parens are designed for categories, so you can segment your code into categories to make it more readable. because the code is in .mand private, they are called the Private category.

-1
source

All Articles