几个月前我制作了一个基于苹果GLPaint的应用程序。
效果很好。
我记录了在屏幕上绘制简单图画的一组点。并将它们保存为点数组(转换为 NSValue)。
我现在正在尝试改进我的应用程序,我再次查看了苹果示例。
他们的数据文件中的数据看起来像这样(我稍微改变了一点):
<data>
AAC8QgAAsEMAAMJCAICoQwAAwkIBBAKRDAADCQgCAnUMAAMJCAACYQwAAwEIAgJRDAADA
QgCAkkMAAMBCAACRQwAAwEIAgJBDAADAQgCAkEM=
</data>
<data>
AACoQgAAnEMAALpCAACdQwAAxEIAAJ1DAAGGGgAAnUMAANpCAICdQwAA4kIAgJ5DAADs
QgCAn0MAAOxCAICfQw==
</data>
所以每个组都是一张图,这比我的 CGPoints plists 更紧凑。
我已成功将 CGPoints 数组转换为数据并读回文件。
但是
当我尝试打开每个形状数据文件时,我得到这个(在 textMate、textEdit、xCode...):
我想了解:
- 苹果使用什么来获取CGPoints列表的这种压缩格式?
- 如何以更易读的方式打开我的数据文件?
Few months ago i made an app based on apple GLPaint.
It works great.
I have recorded sets of points that draw simple drawings on the screen. and saved them as array of points (converted to NSValue).
i am trying to improve my app now and i looked again at apple example.
the data in their data file looks like that (i have changed it a little bit):
<data>
AAC8QgAAsEMAAMJCAICoQwAAwkIBBAKRDAADCQgCAnUMAAMJCAACYQwAAwEIAgJRDAADA
QgCAkkMAAMBCAACRQwAAwEIAgJBDAADAQgCAkEM=
</data>
<data>
AACoQgAAnEMAALpCAACdQwAAxEIAAJ1DAAGGGgAAnUMAANpCAICdQwAA4kIAgJ5DAADs
QgCAn0MAAOxCAICfQw==
</data>
So every group is one drawing and This is way compact then my plists of CGPoints.
I have succeeded to convert the array of CGPoints to data and read the file back.
BUT
When i try to open each shape data file i get this (on textMate, textEdit, xCode...):
I wish to understand:
- What does apple use to get this compressed format of the CGPoints list?
- how can i open my data file in more readable way?
发布评论
评论(2)
Apple 的 Recording.data 文件中的数据 示例应用程序 是包含以下内容的 NSArray 的 XML Plist 表示一堆 NSData 对象,每个对象都包含表示 CGPoint 结构数组的字节。请注意,这取决于 CGFloat 的二进制表示形式和 CGPoint 结构的特定布局,这在编译器或同一编译器的版本之间可能有所不同。
您的屏幕截图似乎是 NSKeyedArchiver 的输出,它更安全,但开销更大。
如果您想要紧凑但仍然可移植的表示形式,您可以手动将各个 CGFloats 序列化为可移植格式的字节数组(这个上一个问题可能会帮助你),然后将字节数组包装在 NSData 中,将 NSData 放入 NSArray 中,并使用
writeToFile:atomically:
将混乱的内容输出到plist 就像苹果一样。The data in Apple's
Recording.data
file in that sample application is the XML Plist representation of an NSArray containing a bunch of NSData objects, each of which contains the bytes representing an array of CGPoint structs. Do note that this depends on the binary representation of a CGFloat and the specific layout of the CGPoint struct, which could differ between compilers or versions of the same compiler.Your screenshot appears to be the output of NSKeyedArchiver, which is safer but has much more overhead.
If you wanted a compact but still portable representation, you could manually serialize the individual CGFloats into a byte array in a portable format (this previous question may help you there) and then wrap the byte arrays in NSData, put the NSDatas into an NSArray, and use
writeToFile:atomically:
to output the mess to a plist like Apple does.这似乎是 Base64。 此页面提到了它:
用于
NSData
,您可以使用+[NSKeyedArchiver archivedDataWithRootObject:]
。This appears to be Base64. This page mentions it:
<data>
is forNSData
, which you can get from an array by using+[NSKeyedArchiver archivedDataWithRootObject:]
.