我对以下代码有疑问。我希望结果multiLineTitle
看起来像这样
Each
Word
Should
Have
Its
Own
Line
但是当我运行这个程序时,multiLineTitle
结束了null
. 谁能发现这个问题?
NSString *title = "Each Word Should Have Its Own Line";
NSString *multiLineTitle;
NSArray *words = [title componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
words = [words filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF != ''"]];
for (int len = 0; len < [words count]; len++){
multiLineTitle = [multiLineTitle stringByAppendingFormat:@"%@ \n", words[len]];
}