ten.textValue = [[NSMutableString alloc]init];
ten.textValue = [NSMutableString stringWithString:textField.text];
I am getting crash at second line.
ten.textValue is NSMutableString.
ten.textValue = [[NSMutableString alloc]init];
ten.textValue = [NSMutableString stringWithString:textField.text];
I am getting crash at second line.
ten.textValue is NSMutableString.
On
It is probably because the text property of UITextField is nil by default, and passing nil to [NSMutableString stringWithString:nil] causes a crash.
You need to make sure the text is not nil when you pass it to be copied, for example like this:
[NSMutableString stringWithString: textField.text ? textField.text : @""]
You should also eliminate the first line - it serves no purpose, because the allocated and assigned value gets overwritten immediately.
When you create your
ten.textValue = [[NSMutableString alloc]init];you are creating an object that you own.When you try to add a string to it in the next line, you are creating an autoreleased string. This is confusing the compiler, which is reporting "hang on - this is an allocated, owned object already".
Instead: