I am very confused regarding selector concept in objective c.Can we mention two methods with same name and different parameters in two different classes .If not how this solve the problem of function overloading.please, answer as it is required very urgent.
I am very confused regarding selector concept in objective c.Can we mention two methods with same name and different parameters in two different classes .If not how this solve the problem of function overloading.please, answer as it is required very urgent.
Objective-C doesn't have support for method overloading; methods that take different types should have different names.
You should not declare two methods with the same name but different parameter type - not in the same class, and not in related classes. It will cause a compiler warning and may not work as expected.
This came as a shock to me just this week, after writing Obj-C for a year.
I am very confused regarding selector concept in objective c.Can we mention two methods with same name and different parameters in two different classes .If not how this solve the problem of function overloading.please, answer as it is required very urgent.
If it's actually unrelated classes, it's fine. If they're related (subclass or whatever), then you can't do it.
Objective-C doesn't have support for method overloading; methods that take different types should have different names.
You should not declare two methods with the same name but different parameter type - not in the same class, and not in related classes. It will cause a compiler warning and may not work as expected.
This came as a shock to me just this week, after writing Obj-C for a year.
The parameter labels are part of the method name - so "initWithTag:" and "initWithTag:data:" are two different method names. If you try get selectors for those methods, then @selector(@"initWithTag:") and @selector(@"initWithTag:data:") would give you two different selectors.
Overloading would be two methods called "initWith:" , but one takes a string and another takes an array. You can't do that.
The code you posted is a good example of what to do instead of overloading - create two methods with two different names to use in different situations.
We have two init methods, One in NSObject class and another in NSString class .Can you explain the purpose of two of above methods? The init of NSObject class I know as it is initialize the instance variables to 0 but the confusion arises when I came across init method of NSString class .
Also I want to know the purpose of initWithBytes:length:encoding: method of NSString class.
We have two init methods, One in NSObject class and another in NSString class .Can you explain the purpose of two of above methods? The init of NSObject class I know as it is initialize the instance variables to 0 but the confusion arises when I came across init method of NSString class .
Also I want to know the purpose of initWithBytes:length:encoding: method of NSString class.
NSString is a subclass of NSObject. NSString's init method IS NSObject's init method. Plus anything additional NSString needs.
The purpose of initWithBytes(etc) is to initialize the string with some specific content based on the contents of the NSData object. (I think the bytes: parameter takes an NSDATA).