• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Getting an NSAttributedString from NSData/NSTextView using Core Data
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Getting an NSAttributedString from NSData/NSTextView using Core Data


  • Subject: Getting an NSAttributedString from NSData/NSTextView using Core Data
  • From: "Hans Kuder" <email@hidden>
  • Date: Mon, 16 Jul 2007 21:44:50 -0400

Hi everyone,
I've got a Core Data app to which I'd like to add searching functionality. I
have a class called MNode, which is a subclass of NSManagedObject. An MNode
stores some of its data in an attribute called nodeData, which is set to
"Binary data" in my object model and is bound to an NSTextView by means of
NSUnarchiveFromData.

Currently this works great - I can save rich text and images in the
NSTextView with no trouble.

To make this data searchable/fetchable, I'd like to keep a plain-text copy
of nodeData as a string attribute in MNode called nodeText. To keep these
two attributes synchronized, MNode has the following method:

- (void)setNodeData:(NSData*)newData
{
NSString *plainText;
[self willChangeValueForKey:@"nodeData"];
[self setPrimitiveValue:newData forKey:@"nodeData"];
[self didChangeValueForKey:@"nodeData"];
NSAttributedString *aString = [[[NSAttributedString alloc]
initWithRTFD:newData documentAttributes:nil] autorelease];
if (aString == nil) {
aString = [[[NSAttributedString alloc] initWithRTF:newData
documentAttributes:nil] autorelease];
}
if (aString == nil) {
NSLog(@"Error getting plain text");
} else {
plainText = [[aString string] copy];
NSLog(@"%@", plainText);
[self willChangeValueForKey:@"nodeText"];
[self setPrimitiveValue:plainText forKey:@"nodeText"];
[self didChangeValueForKey:@"nodeText"];
}
[plainText release];
}

I adapted this from here:
http://www.macgeekery.com/development/searching_rtf_and_rtfd_with_core_data

This method gets called every time nodeData is set, and theoretically should
also set nodeText. Unfortunately, the initWithRTFD:documentAttributes and
initWithRTF:documentAttributes methods of NSAttributedString always return
nil. This happens regardless of whether or not the NSTextView has any
special formatting or images in it.

Any ideas what might be causing the above methods to always return nil? Does
NSTextView store its data in a format different from RTF/RTFD that I should
be checking?

Any help would be greatly appreciated. Thanks!
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Getting an NSAttributedString from NSData/NSTextView using Core Data
      • From: Felix Franz <email@hidden>
  • Prev by Date: Positioning an NSView in an NSWindow
  • Next by Date: Re: Custom NSMenuItem/NSPopupButtonCell Drawing
  • Previous by thread: Re: Positioning an NSView in an NSWindow
  • Next by thread: Re: Getting an NSAttributedString from NSData/NSTextView using Core Data
  • Index(es):
    • Date
    • Thread