if(loanTerms && loanTerms.count>0) {
for(inti =0; i < loanTerms.count; i++) {
NSNumber*term = loanTerms[i];
if(contextManager.deadLineArray.count== loanTerms.count) {
break;
}
[contextManager.deadLineArrayaddObject:[[NSStringstringWithFormat:@"%ld", (long)term.integerValue]stringByAppendingString:@"个月"]];
if(i == loanTerms.count-1) {
contextManager.deadLineString= [contextManager.deadLineString stringByAppendingString:term.stringValue];
}else{
contextManager.deadLineString= [contextManager.deadLineString stringByAppendingString:[NSStringstringWithFormat:@"%@/",term.stringValue]];
}
//DebugLog(@"contextManager.deadLineString = %@", contextManager.deadLineString);
}
}
这样一段代码折腾了很长时间
1,[contextManager.deadLineString stringByAppendingString:[NSStringstringWithFormat:@"%@/",term.stringValue]];直接这样是不行的,必须每次将添加后的值返回来:contextManager.deadLineString= [contextManager.deadLineString stringByAppendingString:[NSStringstringWithFormat:@"%@/",term.stringValue]];这样是正确的
2,contextManager.deadLineString不能是空值,如果是空值添加不上
3,-(NSString*)deadLineString
{
if(!_deadLineString) {
_deadLineString=@"";
}
return_deadLineString;
}
这种是最佳处理方式
如果用 NSMutableString的话,赋值时会报警告。