Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you're used to bindings, then I'd recommend looking at NSValueTransformer; specifically, creating a subclass of that which converts a priority value to a string of exclamation marks. You'd then simply provide the name (the same one used in <code>+setValueTransformer:forName:</code>) as the 'value transformer' attribute in your bindings.</p> <p>For instance, the code would look like so:</p> <pre><code>@interface PriorityTransformer : NSValueTransformer @end @implementation PriorityTransformer + (Class) transformedValueClass { return ( [NSString class] ); } + (BOOL) allowsReverseTransformation { return ( NO ); } - (id) transformedValue: (id) value { // this makes the string creation a bit simpler static unichar chars[MAX_PRIORITY_VALUE] = { 0 }; if ( chars[0] == 0 ) { // ideally you'd use a spinlock or such to ensure it's setup before // another thread uses it int i; for ( i = 0; i &lt; MAX_PRIORITY_VALUE; i++ ) chars[i] = (unichar) '!'; } return ( [NSString stringWithCharacters: chars length: [value unsignedIntegerValue]] ); } @end </code></pre> <p>You would then put this code into the same file as a central class (such as the application delegate) and register it through that class's <code>+initialize</code> method to ensure it's registered in time for any nibs to find it:</p> <pre><code>+ (void) initialize { // +initialize is called for each class in a hierarchy, so always // make sure you're being called for your *own* class, not some sub- or // super-class which doesn't have its own implementation of this method if ( self != [MyClass class] ) return; PriorityTransformer * obj = [[PriorityTransformer alloc] init]; [NSValueTransformer setValueTransformer: obj forName: @"PriorityTransformer"]; [obj release]; // obj is retained by the transformer lookup table } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload