Pregunta

i am coding a program for iPhone using Xcode. i defined some attributes for user interface components like uibutton, uilabel etc in property list file. i defined one attribute as real named "cornerradius". Now, how can i get this value from plist correctly to assign CGFloat? Is property list the best way to define attributes? what are my options, any tutorials you recommend?

in plist: key cornerradius /key real 6.0 /real

in code:

NSDecimal cornerRadius;
cornerRadius = [[[dao libraryItemAtIndex:0] valueForKey:@"cornerradius"] decimalValue];
[layer setCornerRadius:(CGFloat)cornerRadius];
¿Fue útil?

Solución

If you are looking for program wide scope you should use NSUserDefaultsController , keep in mind that with a plist you will be only be able to store and retrieve values, like NSNumber, NSString, NSArray, NSDictionary...

NSUserDefaults * standardUserDefaults = [NSUserDefaults standardUserDefaults];
[standardUserDefaults setObject:[NSNumber numberWithInt:7] forKey:@"someKey"];
[standardUserDefaults synchronize];//save to disk
// now use it
NSNumber * someNumber = [standardUserDefaults objectForKey:@"someKey"];
int someInt = [someNumber intValue];
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top