我需要连接两个 NSStrings ,我写了下面的代码:
NSString *reverseResult = [[NSString alloc] initWithFormat:@""];
NSString *zero = [[NSString alloc] initWithFormat:@"0"];
NSString *one = [[NSString alloc] initWithFormat:@"1"];
int modRes;
while (num != 0) {
modRes = num;
modRes = num % 2;
if (modRes == 0)
[reverseResult stringByAppendingString:zero];
else
[reverseResult stringByAppendingString:one];
num = num / 2;
}
当我调试代码时,我看到“stringByAppendingString”没有做我需要的事情(reverseResult 保持@“”,即使它到达那一行)。
代码有问题吗?