Where should I put this code?

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

  1. merican
    Expand Collapse
    macrumors newbie

    Joined:
    Feb 20, 2012
    #1
    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
    Expand Collapse
    macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    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
     
  3. merican
    Expand Collapse
    thread starter macrumors newbie

    Joined:
    Feb 20, 2012

Share This Page