• 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
What's wrong with this code?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

What's wrong with this code?


  • Subject: What's wrong with this code?
  • From: Larry Fransson <email@hidden>
  • Date: Thu, 6 Apr 2006 00:58:41 -0700

The project is a Core Data document-based application. One attribute of an entity is binary data for rich text and graphics. I'd like to search that RTF/RTFD data. After looking for some time, I found a solution. I created a subclass of NSManagedObject for my entity, and added a method to return an NSString from the data. It seems to work just fine. But the web site I found that helped in the finding of this solution (http://www.macgeekery.com/development/ searching_rtf_and_rtfd_with_core_data )indicates that "Core Data cannot do live searching on transient values....", but that's exactly what I seem to be doing. So here is my solution:

- (NSString *)remarksString
{
[self willAccessValueForKey:@"remarks"];
NSData *remarksData = [self valueForKey:@"remarks"];
[self didAccessValueForKey:@"remarks"];
NSAttributedString *aString = [[[NSAttributedString alloc] initWithRTFD:remarksData documentAttributes:nil] autorelease];
if(aString == nil) {
aString = [[[NSAttributedString alloc] initWithRTF: remarksData documentAttributes:nil] autorelease];
}
if(aString == nil) {
NSLog(@"Error transforming data to string");
}
return [aString string];
}


I'd like to know what's wrong with this. It seems to work the way I want it to, which makes me happy. Is it just a problem of scaling? It works great on the few test records I have, but when I get to a couple thousand, is it likely to get really slow? Or is there some other thing that I'm likely to be breaking?

Larry Fransson
Subcritical
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: What's wrong with this code?
      • From: James Bucanek <email@hidden>
  • Prev by Date: Re: Thread safety issue...
  • Next by Date: Re: +[NSPasteboard pasteboardByFilteringData:ofType:] returns nil
  • Previous by thread: Re: Extending NSArray to make it compatible on Panther
  • Next by thread: Re: What's wrong with this code?
  • Index(es):
    • Date
    • Thread