I've created a library of pre-defined colours for use in Swift and Objective-C and I've rewritten a plug-in for Xcode that previews the colour in the editor so that it works with my library (along with a few other changes).
The plugin currently has a list of the colours that's created. I'm not thrilled with this solution since it means that anytime I change the list of colours I have to modify my code here too. Plus I don't like having a data structure hanging around holding approximately 1500 colours and strings. Doesn't seem to be that efficient or elegant.
What I'd like to do is instead of storing all of the colours in memory is to call the proper function of NSColor when it comes across the function name in the code. I've found that I can check to see if NSColor responds to a selector with the function respondsToSelector: but calling performSelector: doesn't meet my needs since I need the return value from the call.
So is there a way to go from this.
let colourDict [ String : NSColor ] = [
"blackColor" : NSColor.blackColor(),
"whiteColor" : NSColor.whiteColor() ]
...
let foundColour = colourDict[ colourMethodName ]
To something like this.
if ( NColor.respondsToSelector ( Selector ( colourMethodName ) ) {
foundColour = NSColor.performSelector ( Selector ( colourMethodName ) )
}
Obviously it wouldn't be the performSelector: function itself but I'm looking for that type of functionality except that it would be returning back the NSColor object.
Thanks.