Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

-stringByAppendingString: not working

I need to concatenate two NSStrings , I wrote the code below:

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;
}

When I debug the code I see that the "stringByAppendingString" is not doing what I need (reverseResult stays @"", even though it gets to that row).

Is there something wrong with the code?

like image 667
oridahan Avatar asked Dec 14 '12 14:12

oridahan


People also ask

What is the word for not working?

(also kaputt), malfunctioning, nonfunctional, nonoperating.

Is not Working meaning?

Definition of nonworking : not working: a : not employed : not having a paying job Of nonworking mothers who have preschool children, more than a quarter say they would seek paying jobs if reasonably priced child care were available.— Joshua Mendes.


1 Answers

stringByAppendingString returns a new string, it doesn't modify the existing one. You have to store the result in a variable.

like image 141
Joni Avatar answered Oct 05 '22 23:10

Joni