How to save a color in NSUserDefaults in swift?

后端 未结 2 1505
无人共我
无人共我 2021-02-09 15:25

I have a litle problem with saving a color in NSUserDefaults . In objective-c is easy :

-(NSColor *)colorForKey:(NSString *)key{
NSData  *data;
NSColor *color;
         


        
2条回答
  •  广开言路
    2021-02-09 16:30

    Storing an NSColor instance in user defaults

    store the value in aColor in user defaults as the value for key aKey

    NSData *theData=[NSArchiver archivedDataWithRootObject:aColor]; [[NSUserDefaults standardUserDefaults] setObject:theData forKey:aKey];

提交回复
热议问题