0

I've been working on a core data program for a while now. I'm trying to combine attributes of an entity in a text view for saving to PDF and Printing. One of the attributes of the entity uses binary data.

When I execute this:

NSData *myData = [object valueForKey:@"cueNotes"];

...it returns this:

  typedstreamè@
NSMutableDataNSDataNSObjecti[276c]{\rtf1\ansi\ansicpg1252\cocoartf949\cocoasubrtf540
{\fonttbl\f0\fnil\fcharset0 LucidaGrande;}
{\colortbl;\red255\green255\blue255;}
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural\pardirnatural

\f0\fs20 \cf0 step one text}

when I try this:

NSAttributedString* myDataTry = [[[NSAttributedString alloc] initWithRTF:myData documentAttributes:nil] autorelease];

... myDataTry is nil. I read a little about the rtf format and then removed this:

typedstreamè@
NSMutableDataNSDataNSObjecti[276c]  

...from the myData data but still get a nil result. Does anyone have any idea what I'm doing wrong?

Update: After thinking about the first answer I tried this (as well as a couple permutations):

NSString* notesString = [[[NSString alloc] initWithRTF:[object valueForKey:@"cueNotes"] documentAttributes:nil] autorelease];

as well as an allocated string and still no results.

Here is the results of the entity that I'm pulling 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 =     (
);

})

4

1 回答 1

0

当你将像 NSAttributedString 实例这样的实际对象保存到 Core Data 时,你应该将它保存为可转换类型,而不仅仅是数据。这将使您“冷冻干燥”实际实例,然后将其原封不动地恢复原状,无需进一步处理。

于 2010-10-15T20:46:41.793 回答