Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Append a newline to an NSString

I have this:

if (soapResults != nil) {
    soapResults = [soapResults stringByAppendingString:@"\n"];
    }

But I get a warning:

Assignment from distinct Objective-C type on build.

When I run it on device I get:

Program received signal: "EXC_BAD_ACCESS".

from gdb.

Any ideas how to append a newline to an NSString without getting a warning or error?

Any help appreciated // :)

like image 532
Spanky Avatar asked Nov 09 '09 08:11

Spanky


2 Answers

An alternative is: [NSString stringWithFormat: @"%@\n", soapResults] even if the logic is the same!

However, even in the case of stringByAppendingString, it returns a new string but it doesn't change the target, so you have to assign the new string to a new instance of the class NSString.

like image 71
BitDrink Avatar answered Sep 19 '22 15:09

BitDrink


You can try this, it works for me:

NSString *content1 = [messageObject valueForKey:@"content"];
NSString *seprator = @"\n----------------------\n";
NSString *myString = [NSString stringWithFormat:@"%@\n%@\n",seprator,content1];
content = [content stringByAppendingString:myString];

`

like image 43
Alok Srivastava Avatar answered Sep 19 '22 15:09

Alok Srivastava