1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Where should I put this code?

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

  1. macrumors newbie

    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. macrumors 68040


    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. macrumors newbie

    I went with the factory. Thanks!

Share This Page