I am simply writing the following code for testing purpose:
NSString *aStr = [[NSString alloc] initWithFormat:@"Foo"];
aStr = [aStr initWithFormat:@"Bar"];//Crashed here
I am getting the following error:
*** initialization method -initWithFormat:locale:arguments: cannot be sent to an abstract object of class __NSCFString: Create a concrete instance!
If i write the following code same thing happen
NSString *aStr = [NSString alloc];
aStr = [aStr initWithFormat:@"Foo"];
aStr = [aStr initWithFormat:@"Bar"]; //Crashed here
By google I come to know that initWithFormat
will return the NSCFString
Object.
My question is if NSCFString
is derived class of NSString
then why I cannot invoke the initWithFormat
method on NSCFString
. If it is possible to stop the visibility how can I implement in the code without overriding the method in NSCFString
(Derived Class).
In simple word If NSCFString is derived class of NSString then why i cannot call the base class (initWithFormat) method on that?
As per Documentation it returns an
NSString
object initialized by using a given format string as a template into which the remaining argument values are substituted.And also you need to use like that below :-