0
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];

在第 4 行得到错误 error: void value not ignored as it should be

请帮帮我...

4

2 回答 2

1
[mSt appendString:mSt2];

此方法的返回类型为void. 它修改了NSMutableString您调用它的方法(mSt在这种情况下),但不返回任何内容。

所以不要期望返回值。删除NSMutableString *str并直接使用它。

[songHrs addObject:mSt];

由于字符串是可变的,它只是在原地改变自身。无需将结果保存在单独的变量中。事实上,这就是 usingNSMutableString而不是NSString.

于 2010-11-27T19:50:49.590 回答
1

除了 Squeegy 已经写过的关于追加的内容之外,您的第 1、2 和 3 行似乎也损坏了——您应该调用 initWithString 而不是 stringWithString,或者使用 stringWithString 但不使用 alloc。整个结构虽然很混乱,而且没有任何意义——但这可能是出于测试目的。

于 2010-11-27T20:10:13.213 回答