In my iPhone app, I have a appSettings.plist. This allows me, but also others to simply change some parameters. One of the parameters is the predominant color of the app. The .plist looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Red</key>
<integer>255</integer>
<key>Green</key>
<integer>123</integer>
<key>Blue</key>
<integer>124</integer>
<key>compositeRGB</key>
</dict>
</plist>
In my code, I read this file, and try to make a UIColor out of these three numbers. I have to admit that I don't know too much about CGFLoats, and I suspect that that is the cause of my trouble. This is what I do:
-(void)readAppSettings
{
NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [path stringByAppendingPathComponent:@"appSettings.plist"];
NSDictionary *plistDictionary = [[NSDictionary dictionaryWithContentsOfFile:finalPath] retain];
unsigned int RedComponent = [[plistDictionary objectForKey:@"Red"]intValue];
unsigned int GreenComponent = [[plistDictionary objectForKey:@"Green"]intValue];
unsigned int BlueComponent = [[plistDictionary objectForKey:@"Blue"]intValue];
appColor = [UIColor colorWithRed: ((float) RedComponent / 255.0f)
green: ((float) GreenComponent / 255.0f)
blue:((float) BlueComponent / 255.0f)
alpha:1.0f];
}
whenever I try to use appColor
as a UIColor, my app crashes, with the following error:
'-[__NSCFArray CGColor]: unrecognized selector sent to instance 0x7b0ab20'
Could somebody explain to me what I'm doing wrong. You don't have to be polite.