views:

63

answers:

1

Hello,

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?

Thank you,

Loren

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 =     (
);

})

A: 

When you are saving an actual object like a NSAttributedString instances to Core Data, you should save it as a transformable type instead of just data. That will let you "freeze dry" the actual instance and then get it right back unaltered with no further processing required.

TechZen
Would "freeze drying" the data affect the fact that myData is returned as nil?
Loren Zimmer
No, I am pretty sure you are getting a nil attributed string because you are converting the attributed string to raw data instead of RTF when you save it. You are trying to use methods intended for writing to text files within Core Data. You need to avoid all that and save the actual attributed string instance itself in a transformable attribute.
TechZen
do you have an example of what you are talking about?
Loren Zimmer