rockey
rockey

Reputation: 638

cant we append a nsmutable string to another nsmutablestring

NSMutableString *mSt1 = [[NSMutableString alloc] stringWithString:asong.at];
            NSMutableString *mSt = [[NSMutableString alloc] stringWithString:[mSt1 substringWithRange: NSMakeRange (0, 2)]];
            NSMutableString *mSt2 = [[NSMutableString alloc] stringWithString:[mSt1 substringWithRange: NSMakeRange (5, 2)]];
            NSMutableString *str = [mSt appendString:mSt2];
            [songsHrs addObject:str];
            [mSt release];
            [mSt1 release];
            [mSt2 release];

getting the error at line no.4 error: void value not ignored as it ought to be

help me out please...

Upvotes: 0

Views: 286

Answers (2)

Eiko
Eiko

Reputation: 25632

Besides what Squeegy already wrote about appending, your lines 1, 2 and 3 seem also broken - you should call initWithString and not stringWithString, or use stringWithString but no alloc. The whole construct is messy though and doesn't really make sense - but this is for testing purpose probably.

Upvotes: 1

Alex Wayne
Alex Wayne

Reputation: 186984

[mSt appendString:mSt2];

This method has a return type of void. It modifies the NSMutableString you call it on (mSt in this case), but returns nothing.

So don't expect a return value. Delete the NSMutableString *str and just use it directly.

[songHrs addObject:mSt];

Since the string is mutable, it simply changes itself in place. No need to save the result in a separate variable. In fact, this is the entire point of using NSMutableString instead of NSString.

Upvotes: 1

Related Questions