Hi i am new to iphone and starts to learning Obj c.
i have notice the function definition, for some function we are using (-) and for some function we are using (+)
Example:
+ (id)requestWithURL:(NSURL *)theURL
– initWithURL:
what the difference between those two operator / symbol’s usage?
thanks!
In the context of a class definition,
+/-determine whether the methods are instance or class level methods.+indicates the method is class level, and you don’t need an instance to call it.-indicates the method is an instance method, and must be called through an instance of an object.A common example of a static (+) method is
NSString::stringWithFormat, when you call it, you do so without an instance, but rather using the class name:An instance method must be called on an instance of an appropriate object, an example of one would be:
These symbols should not be confused with the mathematical operators
+and-, which can only be applied as part of binary or unary arithmetic expressions.