Using core data binary and string attributes with NSTextView
Using core data binary and string attributes with NSTextView
- Subject: Using core data binary and string attributes with NSTextView
- From: Robert <email@hidden>
- Date: Sat, 17 Oct 2009 16:14:29 -0700
I'm new to core data and bindings and need some help.
In my model, I've got an attribute called "story". This holds text,
so I set the attribute type to string.
I used bindings in IB to connect the story attribute to an NSTextView.
When I ran my app, an exception was thrown. The message in the
console indicated a conflict. It seemed core data was pulling an
attributed string out of the NSTextView, and could not store in in my
model's story attribute which was only a string.
I worked around this my turning off the NSTextView's Rich Text
checkbox in IB. Everything ran fine, NSTextView displayed my data.
Then I added a search field to my app. In IB I set things up to
search the story attribute. It worked great.
Then I noticed that I couldn't save font styles, sizes etc in my
NSTextView. I played around with the model again and made the story
attribute a Binary Data type, and I turned the Rich Text setting back
on for the NSTextView. This worked for saving the story text and font
stuff, but broke searching. It reasons that now that the story
attribute is binary, it can't be search like when it was string.
Now, after a lot of googling, I'm working on a solution that involves
having a new transient attribute in my model of type string (let's
call it storyText) that will mirror the text held in the binary data
story attribute. Instead of my search field using the "story"
attribute, it will use the "storyText" attribute.
To do this, I created .m and .h files for my model, and I'm
implementing the accessor and setter for the storyText attribute. In
the accessor method, I get, using valueForKey, the story object. The
question now is, what do I do with it? It appears that this object is
an NSData object. Am I correct about this? What do I do with it to
get it into an NSAttributed string on which I can extract the string?
Hope I've stated all the facts clearly and that someone can enlighten
me.
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