使用 NSUserDefaults 保存 CGPoints 列表

发布于 2024-10-09 19:29:54 字数 264 浏览 0 评论 0原文

我有一堆来自 CCTMXLayer 的 CGPoints,我想保存到 NSUserDefaults,但似乎无法找到一种优雅的方法。

最初我希望用 NSMutableSet 保存一个 NSDictionary 来保存一个包含多个 NSValues (valueWithCGPoint) 的值。据我所知,NSUserDefaults 不支持 NSMutableSet 或 NSValue。

此时,我正在考虑将 CGPoint 的 x&y 值保存为字符串,然后根据需要来回转换它。

I have a bunch of CGPoints from a CCTMXLayer I want to save to NSUserDefaults but cannot seem to figure out an elegant way of doing so.

Originally I was hoping to save an NSDictionary with an NSMutableSet for a value containing several NSValues (valueWithCGPoint). From what I can tell neither NSMutableSet or NSValue is supported by NSUserDefaults.

At this point I am considering saving the x&y values of the CGPoint as a string and just converting it back and forth as needed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

潜移默化 2024-10-16 19:29:54

存在一对函数 NSStringFromCGPointCGPointFromString。您可以使用它们来生成表示序列化点的字符串数组,然后在完成后转换回来。

There exists a pair of functions NSStringFromCGPoint and CGPointFromString. You can use these to produce an array of strings representing the points for serialization, and then convert back when you're finished.

彩虹直至黑白 2024-10-16 19:29:54

将它们放入 NSValue 对象中。一旦它们到达那里,您就可以将 NSValues 写入磁盘(因为它们符合 )或将它们放入 NSUserDefaults 中> 或其他什么。

Box them in NSValue objects. Once they're in there, you can write the NSValues out to disk (since they conform to <NSCoding>) or put them in NSUserDefaults or whatever.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文