In Objective-C, some methods are preceded by plus and minus signs. Is this correct?
仅有的幸福
仅有的幸福 2017-05-02 09:24:35
0
1
665

In Objective-C, some methods in classes have a plus sign and some have a - minus sign. The difference between the two is as follows:

Methods preceded by a plus sign ( ) are class methods. This type of method can be called directly using the class name. Its main function is to create an instance. Some people call it a factory method for creating instances. (Similar to the static methods of classes in PHP, called through className::methodName)
Methods preceded by a minus sign (-) are instance methods and must be called using an instance of the class. (Similar to ordinary classes in PHP, if you want to call a method, you must first instantiate an object and then call it through $obj->methodName)

仅有的幸福
仅有的幸福

reply all(1)
仅有的幸福

That’s basically correct, but class methods are not only used to create instances. They are basically equivalent to PHP’s static methods. You can use static methods however you want. No one stipulates that static methods can only create instances.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template