obj c does not have strict private methods. This is determined by its method calling mechanism. Calling a certain method of an object in obj c is actually sending a message to the object, and the object sees if it can handle the message. , if it can be handled, the corresponding method will be called to implement it. If it cannot be handled, an exception will be thrown. This is completely a runtime action. So even if a method is not declared in the header file, it can still be called at runtime, and it is no different than if you declared it in the header file. At most, Xcode will give you a warning.
The same goes for static methods, because a class itself is also an object. Calling a static method means sending a message to this object.
The so-called private method (not defined in the header file), I personally think is more of a constraint that programmers place on themselves. For example, if it is not placed in the header file, it means that it is not exposed. This method is You don't want it to be called outside, although you can still use it if you want to.
Refer to this article, it’s very detailed and clear: http://blog.jobbole.com/45963/
Yes, categories and extensions in interface are equivalent to private methods.
Category: class name + extension method; extension: @implementation area
You can search for it.
All methods declared in .h are public by default.
If you want it to be private, there is no need to declare it in .h, just implement it directly in .m. It is recommended that all private methods start with p_, ex:
- (void) p_myFirstMethod
{
//todo..
}
It is recommended to take a look at http://blog.sunnyxx.com/2014/04/13/objc_dig_interface/
obj c does not have strict private methods. This is determined by its method calling mechanism. Calling a certain method of an object in obj c is actually sending a message to the object, and the object sees if it can handle the message. , if it can be handled, the corresponding method will be called to implement it. If it cannot be handled, an exception will be thrown. This is completely a runtime action. So even if a method is not declared in the header file, it can still be called at runtime, and it is no different than if you declared it in the header file. At most, Xcode will give you a warning.
The same goes for static methods, because a class itself is also an object. Calling a static method means sending a message to this object.
The so-called private method (not defined in the header file), I personally think is more of a constraint that programmers place on themselves. For example, if it is not placed in the header file, it means that it is not exposed. This method is You don't want it to be called outside, although you can still use it if you want to.
Refer to this article, it’s very detailed and clear: http://blog.jobbole.com/45963/
Yes, categories and extensions in interface are equivalent to private methods.
Category: class name + extension method; extension: @implementation area
You can search for it.
All methods declared in .h are public by default.
If you want it to be private, there is no need to declare it in .h, just implement it directly in .m. It is recommended that all private methods start with p_, ex:
- (void) p_myFirstMethod
{
//todo..
}