Reading rtf information from entity entries to NSString
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] init开发者_如何学CWithRTF:[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.
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.
精彩评论