In the data model I have defined color as variable attribute and for this it has specified ColorTransformer it works, With the help of a single transformer, I can bind it with ColorPicker, save the document and open it. But when I try to get it from code:
escocolor * color = corner Colour; NSLog (@ "corner color =% @ \ n% @", color, color class);
I have found the purpose of NSMutableConcreteData:
bezierMesh [22,164: 730,708] corner color = & lt; 040b7374 7265616d 74,797,065 6481e803 84,014,084 8484074e 53436f6c 6f720084 84084e53 4f626a65 63740085 84016301 84046666 66660183 6eb7613d 8357703e 3e8352b8 1e3f86 & gt; NSConcreteMutableData Amendments getter and does not help them setter:
- (NSColor *) color {[self willAccessValueForKey: @ "color" ]; NSDT * color data = [self-esteemed: @ "color"]; [Self-made AccessValueForKey: @ "color"]; If (colorata == zero) {return zero; } Enkolar * Color = [NSKAdNeCeCeCeCejectedAdvancedToddataDataDataData]; The color of the return; } - (zero) set collar: (nscillor *) color {nslog (@ "--------------> color set% @", color); NSDTA * The Data = [stored on NSACriteDataAbject: Color]; [Will Will Changewolegore: @ "Color"]; [Auto setprimitative value: datatai for: @ "color"]; [Self-made variables: @ "color"]; }
This causes an error:
[NSKeyedUnarchiver initForReadingWithData:]: can not be decoded by non-stop collection NSKeyedUnarchiver
How to get the color NSColor?
Here's a NSString
& lt; -> NSColor
I wrote a few times ago, which is designed to store colors using RGB values within NSUserDefaults
because I have the default using NSData did not like
objects:
StringColourTransformer.h:
@interface StringColourTransformer: NSValueTransformer + (NSString *) toString: (NSColor *) value; + (NSColor *) String: (NSString *) value; @end
StringColourTransformer.m:
#import "StringColourTransformer.h" @implementation StringColourTransformer + (NSString *) toString: (NSColor *) value { StringColor Transformers * Transformer = [[String Collar Transformer Alok] init]; NSString * str = [Transformer reverse transcript value: value]; Return str; } + (NSColor *) String: (NSString *) value {StringColourTransformer * Transformer = [[String Collar Transformer Alok] init]; NSColor * color = (NSColor *) [Transformer changed value: value]; The color of the return; } + (Class) changed value class {returns [enclosure class]; } + (BOOL) allowrevers Transformation {return yes; } - Value converted (id): (id) value {CGFloat r = 0.0, g = 0.0, b = 0.0, a = 1.0; // Only NSString classes are reverse-transworn if ([valueKindOfClass: [NSString class]]) {NSString * stringValue = (NSString *) value; sscanf ([stringValue UTF8String], #ifdef __x86_64 "% lf% lf% lf% lf", #else "% f% f% f% f", #endif & amp; r, & amp; G, and B & Amp; A); } Returns [Encooler color with-silicated red: R green: g blue: B alpha: A]; } - (ID) Reverse Transformed Value: (ID) Value {CGFloat r = 0.0, g = 0.0, b = 0.0, a = 1.0; // Only nssolar squares are converted if ([value iskindoff class: [enclosure class]]) {enocholar * color value = (nscillor *) value; Nscillore * converted = [colored colored coloring pattern spacingname: @ "nscilbrated rgbcularspace"]; [Converted Red: And R Green: And G Blue: & amp; B alpha: & amp; a;); } Return [NSString stringWithFormat: @ "% 3.f% .3f% .3f% .3f", r, g, b, a]; } @end
As you can see I have provided some class methods to make it easier using the code ( toString
and FromString
).
It should be registered early in the life cycle of the app so that its use can be used to change the values within the IB (this is called a singleton where _stringColourTransformer
is example Variable):
_stringColourTransformer = [[string collar transformer light] init]; [NSValueTransformer setValueTransformer: _stringColourTransformer forName: @ "StringColor Transformer"];
And the conversion is as simple:
NSColor * color = [StringColourTransformer fromString: @ "1.0 1.0 0.0 1.0"]; Note: By looking at the code I can now probably use [NSValueTranformer valueTransformerForName:]
in toString
/ string
Instead of making a new instance every time, it is probably less expensive.
Comments
Post a Comment