theomen
theomen

Reputation: 919

NSMutableString is not appending, it's allways null

I'm trying to set a NSMutablearray, but always get null value, it doesn't update with different values on the iterations. Here is the code:

NSMutableString *tipo = [NSMutableString stringWithString:@""];

        if (self.canas.on){
             [tipo stringByAppendingString: @"0"];   
        }

        if (self.copas.on){
            if ([tipo length]==0){
                 [tipo stringByAppendingString: @"1"];

            }else{
                [tipo stringByAppendingString:@",1"];
            }
        }

        if (self.comer.on){
            if ([tipo length]==0){
             [tipo stringByAppendingString: @"2"];

        }else{
            [tipo stringByAppendingString:@",2"];
            }
        }

Many thanks

Upvotes: 0

Views: 163

Answers (1)

knuku
knuku

Reputation: 6102

Because you should use appendString: method, NOT stringByAppendingString:.

The difference is that the first does append the argument to the receiver while the second just returns such value (the receiver remains intact). The second message could be send to NSString while the first is only for NSMutableString.

Hope you see the difference.

Upvotes: 4

Related Questions