How do I perform string manipulation in NSValueTransformer?
I have a table column that I am binding to a value in NSArrayController
. What I am trying to do is display only a substring of the actual value in an array controller. What I'm trying to do so far is to subclass NSValueTransformer
and then do string manipulation in the method transformedValue
. However, I can't figure out how to get the input value converted to a string (it's a type NSConcreteValue
) and maybe there is an easier way to do it without value converters.
a source to share
It looks like you are doing presentation-side formatting, in which case you should use a formatter instead.
Again, if it is a string containing multiple values (for example, something like "42 to 100"), you must make a model object out of it and store them in the array controller. Then you can bind the table columns to specific properties of the model objects, and you don't have to worry about splitting the string and then reassembling it (except when you load and then save the model).
Edit: Nothing. I have not seen that the values of the NSValues object and not NSStrings.
a source to share
You can get a string representation of any object using a method -description
, but for NSValue instances, it is unlikely to print anything particularly meaningful. In other words, it's up to your value converter to interpret the passed object and create a string. If it is an NSValue instance, the question is what data type this instance contains. Once you know this, you can write code to represent it as a string (similar to NSStringFromRect()
).
a source to share