views:

26

answers:

1

Hi All, I'm writing an NSString category that requires an NSNumberFormatter. I'm stuck between initing and releasing one every time my category is used to print a string in a certain way or initing the formatter in my app and passing it through. The NSNumberFormatter has a couple of config calls run on it first to make it work just right and repeating that in various places in my app just seems wrong. And though I could create one formatter in the main app delegate and let anyone grab it when using one of my category additions, I think that's more of a hack than an elegant solution. So, does creating and destroying an NSNumberFormatter in an NSString Category's convenience method sound good enough?

Cheers, Craig

A: 

D'oh the answer seems to be a static variable in the category. Somehow I'd gotten hold of the idea that Objective-C couldn't do that. But it can so that's what I'm using.

Craig