Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

merican

macrumors newbie
Original poster
Feb 20, 2012
2
0
Say I want to add a method somewhere that allows the parsing of an NSString into NSColor, as well as a method for printing out a NSColor into a NSString; The NSStrings have the same syntax of an SVG's color attribute. Where should I be adding these two methods? Should I write a new class "NSColorParser" and "NSColorPrinter" and add the methods there or create a new category for NSColor, adding methods "colorFromSVGAttribute:" and "svgAttributeValue"?
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
Wherever makes most sense to you. They should be class methods if they are on a utility class. It seems like a factory on NSColor is reasonable for getting an NSColor from the NSString. If you are adding these to NSColor, an instance method to get the NSString with your representation would work fine. Make sure to autorelease the objects you return if you use the names in your post.

-Lee
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.