• 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
Re: CoreData, TextView and Bindings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CoreData, TextView and Bindings


  • Subject: Re: CoreData, TextView and Bindings
  • From: Keith Wilson <email@hidden>
  • Date: Thu, 1 Dec 2005 18:40:43 +1100

Hi all,

Anyone else having problems with Bindings and RTFD Text Views?

My NSTextView started to crash again.

So my advice is DO NOT Bind a RTFD NSTextView using NSUnarchiveFromData as the Value Transformer.

I have removed the binding and replaced it with glue code (so far no crashes):

To get the data

if(data)
attribString = [[NSAttributedString alloc] initWithRTFD:data documentAttributes:nil];
else
attribString = [[NSAttributedString alloc] init];


and to save the data:

NSData *data = [attribString RTFDFromRange:NSMakeRange(0, [attribString length]) documentAttributes:nil];

Keith

On 01/12/2005, at 2:44 PM, Keith Wilson wrote:

Hi, (I'm new here)

I've just sent this one off as a bug report to Apple but I'm still scared of a crash - that is, maybe I didn't really find the problem.

Anyone got any ideas?

The top half of my screen contains a diagram. The bottom half of the screen has a TabView - one of the tabs displays a NSTextView that has all functions ticked (ie it's RTFD). The user can drag whatever he/she likes into the NSTextView (text, pics, webpages, etc) and then save it to the SQLite database. As the user clicks around the diagram in the top half of the screen, the info in the TabView is refreshed to whatever is stored in the database for the clicked-on object.

In my ManagedObjectModel the Attribute that stores the TextView content has DataType Binary.

I initially bound the contents of the TextView as an attributedString using NSUnarchiveFromData for the Value Transformer. This sort of worked but I lost some richness in the info such as HTML tables. I also ran into the occasional crash. Tried everything to avoid it but every so often it crashed with an error in -[NSCFDictionary setObject:forKey:] . I assume that the NSDictionary was being told to set a nil value (or for a nil key).

I then bound the TextView via a "data" binding again using NSUnarchiveFromData as the Value Transformer. This worked much better because the richness of the page was retained BUT it also crashed if the value in the database had never been initialized (ie it tried to handle a nil data object).

So I had to over-ride the call to get the data as follows:

// ********************************************************************** *******
-(NSData*)textData
{
NSData *data = nil;
[self willAccessValueForKey:@"story"];
data = [self primitiveValueForKey:@"story"];
[self didAccessValueForKey:@"story"];
if( ! data)
{ NSAttributedString *attributedString = [[[NSAttributedString alloc] init] autorelease];
data = [attributedString RTFDFromRange:NSMakeRange(0, 0) documentAttributes:nil];
}
return data;
}
// ********************************************************************** *******


Assigning a dummy attributedString and then converting it to a NSData object as above seems to work for me so far. No crashes yet.

So maybe the CoreData methods that get the bound values for TextView using NSUnarchiveFromData need to be fixed.

is this a known problem?

Regards Keith from Down Under


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40bigpond.net.au


This email sent to email@hidden

_______________________________________________ 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
References: 
 >CoreData, TextView and Bindings (From: Keith Wilson <email@hidden>)

  • Prev by Date: NSSearchField _sendPartialString exception
  • Previous by thread: CoreData, TextView and Bindings
  • Next by thread: change app name in dock on the fly
  • Index(es):
    • Date
    • Thread