Objective C - Multi line string using stringByAppendingFormat
I'm having an issue with the following code. I want the resultant
multiLineTitle to look like this
Each
Word
Should
Have
Its
Own
Line
But when I run this program, multiLineTitle ends up null. Can anyone spot
the issue?
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]];
}
No comments:
Post a Comment