From an earlier chapter, and on this forum, I learned that the better way to initialize an object is the class method, if available. Rather dan alloc init.
So, I would expect:
NSMutableString *str = [NSMutableString string];
It was said that this is better, regarding memory management.
Why do we use here alloc init?
(In first example).
Obviously, because it doesn’t work:
NSMutableString *zin = [NSMutableString string]; [zin appendString:@"Ajax wint de wereldcup"]; [zin writeToFile:@"/temp/ajax.txt" atomically:YES encoding:NSUTF8StringEncoding error:NULL];
But WHY not?
And am I right to conclude that, when I go write my own code, I better stick to alloc init methods than the class methods?