|
|
saving/reading RTFD files
|
|
|
|
Mac Elite
Join Date: Jan 2003
Location: NYC
Status:
Offline
|
|
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
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Sep 2000
Location: Norfolk, Va
Status:
Offline
|
|
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
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Jan 2003
Location: NYC
Status:
Offline
|
|
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?
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
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'."
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Jan 2003
Location: NYC
Status:
Offline
|
|
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)initWithRTFD NSData *)rtfdData documentAttributes NSDictionary **)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.
)
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Sep 2000
Location: Norfolk, Va
Status:
Offline
|
|
NSAttributedString *description = [[NSAttributedString alloc] initWithRTFD:rtfContents documentAttributes:NULL];
No?
|
you are not your signature
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Jan 2003
Location: NYC
Status:
Offline
|
|
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 Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|