I'm using NSString in my classes and often need to copy string value to another class. But my question is how should I initialize string in, for example init?
(value is class member and the following calls are in init)
value = [NSString stringWithCString:inStrning encoding:NSASCIIStringEncoding];
or
value = [[NSString alloc] initWithCString:inStrning encoding:NSASCIIStringEncoding];
What is the difference here? Does a memory allocated in 1st call released when init finishes?
I'm using value as a assign property. Would it be better to use copy?
And what about copying string when I'm passing it to class using some method? Example:
-(id) initWithObjectTypeStr:(NSString*)inTypeStr
{
...
objectTypeStr = [NSString stringWithString:inType];
//or
objectTypeStr = [[NSString alloc] initWithString:inType];
}
objectTypeStr is not defined as property so it has default properties (assign I think).
What is the best practice to use in this case?