Where should I put this code?

Discussion in 'Mac Programming' started by merican, Feb 20, 2012.

  1. merican macrumors newbie

    Feb 20, 2012
    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"?
  2. lee1210 macrumors 68040


    Jan 10, 2005
    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.

  3. merican thread starter macrumors newbie

    Feb 20, 2012

Share This Page