Objective-C 将 NSColor 保存在 NSUserDefaults 中
如何保存点的颜色,以便当应用程序打开和关闭时,点是用户上次设置的颜色?
有人可以向我解释如何使用 NSUserDefaults 以及在哪些方法中声明 NSUserDefaults 吗?
到目前为止,我有这个:
NSData *data = [NSArchiver archivedDataWithRootObject:color];
[[NSUserDefaults standardUserDefaults] setObject:data forKey:@"MyColor"];
NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:@"MyColor"];
NSColor *color = [NSUnarchiver unarchiveObjectWithData:data];
我遵循的教程链接: http://www.mactech.com/articles/mactech /Vol.25/25.04/2504RoadtoCode/index.html
How do you save the color of the dot so that when the app is opened and closed the dot is the color it was last set to by the user?
Could someone explain to me how to use NSUserDefaults
and in which methods to declare NSUserDefaults
.
So far i have this:
NSData *data = [NSArchiver archivedDataWithRootObject:color];
[[NSUserDefaults standardUserDefaults] setObject:data forKey:@"MyColor"];
NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:@"MyColor"];
NSColor *color = [NSUnarchiver unarchiveObjectWithData:data];
Link for tutorial I followed:
http://www.mactech.com/articles/mactech/Vol.25/25.04/2504RoadtoCode/index.html
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这就是我使用的:
This is what I use: