为什么我的NSSMutableString可能不安全?

Tom*_*ulc 2 cocoa-touch objective-c nsmutablestring

为什么我的NSMutableString潜在不安全?我搜索了这个但找不到任何东西.

int hour = [number intValue] / 3600; 

NSMutableString *time = [[NSMutableString alloc] initWithString:@""];

if (hour < 9) {
    [time appendFormat:@"0"];
    [time appendFormat:[NSMutableString stringWithFormat:@"%d:", hour]];
}
Run Code Online (Sandbox Code Playgroud)

它出什么问题了?这是我第一次看到这个.

woz*_*woz 10

改变这个:

[time appendFormat:[NSMutableString stringWithFormat:@"%d:", hour]];
Run Code Online (Sandbox Code Playgroud)

对此:

[time appendFormat:@"%d:", hour];
Run Code Online (Sandbox Code Playgroud)

appendFormat方法需要你传递一个字符串格式,而不是一个NSMutableString.此屏幕截图显示:

在此输入图像描述

  • 当然,这是答案.但是你可能想稍微解释一下.:) (2认同)