从实体条目读取rtf信息到NSString
我有一个实体(名为 Song),其中一个属性是二进制数据(rtf 字段),我用它来存储关于歌曲的和弦图表或音符。我需要能够打印该字段以及该实体的其他字符串字段。我已经尝试了我能想到的每一种排列:
NSString* notesString = [[[NSString alloc] initWithRTF:[object valueForKey:@"cueNotes"] documentAttributes:nil] autorelease];
我已经成功地将 `[object valueForKey:@"cueNotes"] 解析为 NSData 并查看了 rtf 格式的数据,但是当我尝试 initWithRTF 时,我得到了 null 结果。
以下是我从中提取此数据的实体的日志示例:
2010-10-30 00:47:32.867 lzshow7.2[4222:10b] <NSManagedObject: 0x2a4850> (entity: Song; id: 0x26a030 <x-coredata:///Song/t172F066B-285C-4125-B2FA-CFFA6A353D102> ; data: {
cueName = Stupid;
cueNo = 001;
cueNotes = <040b7479 70656473 74726561 6d8103e8 84014084 84840d4e 534d7574 61626c65 44617461 00848406 4e534461 74610084 8408>;
songToEffect = (
);
songToInstrument = (
);
})
任何人都可以提供的任何帮助将不胜感激。
I have an entity (named Song) that one of the Attributes is binary data (a rtf field) that I use to to store chord charts or notes about a song. I need to be able to print this field along with the other string fields of this entity. I have tried every permutation of this I can think of:
NSString* notesString = [[[NSString alloc] initWithRTF:[object valueForKey:@"cueNotes"] documentAttributes:nil] autorelease];
I have been successfull parsing the `[object valueForKey:@"cueNotes"] to NSData and seeing the rtf formated data, but when I try initWithRTF I get a null result.
Here is an example of a log of the entity that I'm pulling this Data from:
2010-10-30 00:47:32.867 lzshow7.2[4222:10b] <NSManagedObject: 0x2a4850> (entity: Song; id: 0x26a030 <x-coredata:///Song/t172F066B-285C-4125-B2FA-CFFA6A353D102> ; data: {
cueName = Stupid;
cueNo = 001;
cueNotes = <040b7479 70656473 74726561 6d8103e8 84014084 84840d4e 534d7574 61626c65 44617461 00848406 4e534461 74610084 8408>;
songToEffect = (
);
songToInstrument = (
);
})
Any help that anyone could provide would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
initWithRTF:是NSAttributedString的一个方法; NSString 不会响应该选择器并返回 nil,因此您只需更改类名即可解决此问题。
你的编译器肯定已经警告过你了——我建议你不要忽略编译器警告,这样可以省去很多麻烦。
另外, nil 应该只用于 id - 因为文档属性不是这种情况,你应该在那里使用 NULL 。
initWithRTF: is a method of NSAttributedString; NSString won't respond to that selector and will return nil, so you have to just change the class name to fix this problem.
Your compiler must have warned you there - I would advise you not to ignore compiler warnings, it saves a lot of trouble.
Also, nil should be only used in place for id - since this is not the case for the document attributes you ought to use NULL there instead.