Because -initWithFormat: returns an object different from the one returned by +alloc , i.e. an object different from the one pointed to by myString . This is why you should always combine +alloc with -initβ¦
This situation is common in class clusters such as NSString . +alloc returns a common string object, then -initWithFormat: resolves a specific subclass of NSString , frees the current object created by +alloc , creates a new object from a specific subclass of NSString , and then returns this new object.
user557219
source share