The scenario might sound specific, but I am confident you’ve encountered something similar before. You need to construct an array, with a known number of duplicates of a string. Perhaps you’re constructing a template, and need a fixed number of placeholder elements, or you’re parameterizing a query and need a dynamic number of placeholders. In either case, you were probably left writing a rather ugly bit of logic in the middle of a routine that was otherwise focused on the task at hand.
I found myself in a similar situation and put together the following Objective-C category:
There is not much going on here, but the nice thing is that it provides a clean interface for constructing an NSArray with a specified number of duplicates.
Hopefully this saves you time on your next iOS or Mac app!