From what you describe, it sounds like what you really want is a function to find a color's complement, not its inverse. Inverting means something different in this context.
Here's a StackOverflow question regarding complements in JavaScript. Perhaps some of the code is adaptable?
Here is some interesting and potentially useful info about the various ways color can be worked with in Cocoa color spaces. From what it looks like here, if you can use the HSV color space, then the complement of a color could be found by simply taking hue > 179 ? hue -= 180 : hue = += 180
, since the hues are defined around the color wheel in a full circle.