Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > saving/reading RTFD files

saving/reading RTFD files
Thread Tools
MaxPower2k3
Mac Elite
Join Date: Jan 2003
Location: NYC
Status: Offline
Reply With Quote
Jul 4, 2003, 11:51 PM
 
Hi, i'm trying to save the contents of an NSTextView to an RTFD file and then open it again later and read the contents into another NSTextView. The file saves fine (i can open it in terminal and all of the formatting seems to be in tact) and using this line:

Code:
NSData *rtfContents = [NSData dataWithContentsOfFile:[selectedPath stringByAppendingString:@".desc"]];
i can read the file fine (confirmed using [rtfContents length]) but when i call this line:

Code:
[description initWithRTFD:rtfContents documentAttributes:NULL];
it doesn't read rtfContents... when i call [description length] it's 0. So, my question is, how do i get it to read the NSData object? Is there something i should put in documentAttributes? (and if so, how do i format that?)


Thanks,
Max
     
Gametes
Mac Elite
Join Date: Sep 2000
Location: Norfolk, Va
Status: Offline
Reply With Quote
Jul 5, 2003, 12:37 AM
 
What kind of object is description?
Also, are these lines both in the same method? If not you may have some retainment issues.
you are not your signature
     
MaxPower2k3  (op)
Mac Elite
Join Date: Jan 2003
Location: NYC
Status: Offline
Reply With Quote
Jul 5, 2003, 12:51 AM
 
Originally posted by Gametes:
What kind of object is description?
Also, are these lines both in the same method? If not you may have some retainment issues.
yeah, they're both in the same method. description is an NSAttributedString.

initWithRTFD is in 'NSAttributedString Additions' so is there anything special i have to do to get that functionality?
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Jul 5, 2003, 05:10 AM
 
It looks like the culprit is right there:
Code:
[description initWithRTFD:rtfContents documentAttributes:NULL];
You're discarding the return value of the init method, and thus not receiving the attributed string. This is why allocation and initialization should always be combined into one line--otherwise it's easy to forget that init isn't guaranteed to return the same object you sent the message to.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
MaxPower2k3  (op)
Mac Elite
Join Date: Jan 2003
Location: NYC
Status: Offline
Reply With Quote
Jul 5, 2003, 11:04 AM
 
Originally posted by Chuckit:
It looks like the culprit is right there:
Code:
[description initWithRTFD:rtfContents documentAttributes:NULL];
You're discarding the return value of the init method, and thus not receiving the attributed string. This is why allocation and initialization should always be combined into one line--otherwise it's easy to forget that init isn't guaranteed to return the same object you sent the message to.
nope, that's not it either... I've tried it both ways and neither work

edit: here's the initWithRTFD entry from the application kit reference:

initWithRTFD:documentAttributes:



- (id)initWithRTFDNSData *)rtfdData documentAttributesNSDictionary **)docAttributes
Initializes a new NSAttributedString by decoding the stream of RTFD commands and data contained in rtfdData. Also returns by reference in docAttributes a dictionary containing document-level attributes described in �Constants�. docAttributes may be NULL, in which case no document attributes are returned. Returns self, or nil if rtfData can�t be decoded.
so the line:
Code:
NSAttributedString *description = [description initWithRTFD:rtfContents documentAttributes:NULL];
would cause description to be either self or nil, no? in which case, the size is still 0, so it must be returning nil.
( Last edited by MaxPower2k3; Jul 5, 2003 at 11:11 AM. )
     
Gametes
Mac Elite
Join Date: Sep 2000
Location: Norfolk, Va
Status: Offline
Reply With Quote
Jul 5, 2003, 11:54 AM
 
NSAttributedString *description = [[NSAttributedString alloc] initWithRTFD:rtfContents documentAttributes:NULL];

No?
you are not your signature
     
MaxPower2k3  (op)
Mac Elite
Join Date: Jan 2003
Location: NYC
Status: Offline
Reply With Quote
Jul 5, 2003, 12:06 PM
 
Originally posted by Gametes:
NSAttributedString *description = [[NSAttributedString alloc] initWithRTFD:rtfContents documentAttributes:NULL];

No?
THANK YOU! that worked! i'm somewhat new to Obj-C and i couldn't figure out for the life of me why it didn't work. thank you so much
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 09:02 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,