Re: Converting an AttributedString into NSData for an NSTextView
Re: Converting an AttributedString into NSData for an NSTextView
- Subject: Re: Converting an AttributedString into NSData for an NSTextView
- From: Keary Suska <email@hidden>
- Date: Sat, 25 Sep 2010 10:31:51 -0600
On Sep 25, 2010, at 10:06 AM, Brad Stone wrote:
> I've been programming in Cocoa for 12 months now so I may not understand the subject fully but my NSTextView Data binding is connected to a Core Data attribute of type "Binary Data" (NSData) and this works when I manually type in text, set some attributes like underline or font, save it and reopen it.
Yes--don't make assumptions about how the API works. You'll just end up saying something nonsensical, and respondents can't do much more than point that fact out.
Also, if you want useful answers to questions, you need to explain specifically what you need to accomplish, and the conditions under which you need to accomplish it. E.g., bindings will usually change an entire scenario.
> Since I have 4,000 files to cycle through I want to do this all programatically. To simplify things I tried to do this with an NSString instead of an NSAttributableString. I wrote a test app that creates a new document, pulls the entity "newNote" and uses the following code to set the NSData object:
>
> NSData *noteData = [s dataUsingEncoding:NSUnicodeStringEncoding];
> [newNote setValue:noteData forKey:@"noteData"];
>
> I then save the document and loop around again. This works fine with the NSString. After the 4,000 are loaded in, if I open one of the documents in my interface and look in the textView I see the string. I guess don't fully understand how to repeat this process with an AttributedString. I don't see how NSTextStorage applies in this scenario. Maybe I'm skipping a step.
What, specifically, don't you get? What method calls have you tried? Have you read the "Attributed String Programming Guide"?
> On Sep 25, 2010, at 11:28 AM, Keary Suska wrote:
>
>>
>> On Sep 25, 2010, at 9:12 AM, Brad Stone wrote:
>>
>>> I have an NSMutableString that I want to set as the NSData source for an NSTextView. I'm stuck and don't know how to do it. I'm importing about 4,000 XML files and I have to programmatically create the attributedString for each one, there's no way around it.
>>>
>>> How do I convert an NSMutableString to NSData so it can be the data source for an NSTextView?
>>
>> NSTextView doesn't use NSData as its "data source"--it uses NSTextStorage. You can get its content as a mutable string using -mutableString and manipulate it.
Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"
_______________________________________________
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