FROM : Alastair Houghton
DATE : Sat Jan 19 00:30:33 2008
On 18 Jan 2008, at 20:17, Duncan Champney wrote:
> I'm not sure I'm reading the documentation correctly, however.
> Here's the code I'm trying to use:
>
> NSString* theURLName = [NSString stringWithFormat:
> NSLocalizedString(@FW_URL_PREFIX ,nil), theDocumentName];
>
> theFW_URL = [NSURL URLWithString:theURLString];
>
> //Create an NSAttributedString to hold the RTF description of
> the URL.
> theRTF_string= [[NSAttributedString alloc] initWithString:
> theURLName];
> theStringRange.location = 0;
> theStringRange.length = [theURLName length];
> theAttributesDict =
> [NSDictionary dictionaryWithObjects:[NSArray
> arrayWithObjects: theFW_URL, nil]
> forKeys: [NSArray
> arrayWithObjects:NSLinkAttributeName, nil]
> ];
> NSData* the_RTF_data = [theRTF_string RTFFromRange:
> theStringRange documentAttributes:theAttributesDict];
No, that's not right. The attributes need to be set in the attributed
string. The document attributes are something else entirely (more
specifically, they contain information about the *document*, not text
attributes which is what NSLinkAttributeName is). You probably want to
do -initWithString:attributes: rather than just -initWithString:, then
pass nil for the documentAttributes: argument.
Also, consider using -dictionaryWithObjectsAndKeys: or -
dictionaryWithObject:forKey: rather than -
dictionaryWithObjects:forKeys:. They're more efficient and involve
less typing too :-)
Kind regards,
Alastair.
p.s. Please copy the list on replies; that way others with similar
questions will be able to find the answers they need.
--
http://alastairs-place.net
DATE : Sat Jan 19 00:30:33 2008
On 18 Jan 2008, at 20:17, Duncan Champney wrote:
> I'm not sure I'm reading the documentation correctly, however.
> Here's the code I'm trying to use:
>
> NSString* theURLName = [NSString stringWithFormat:
> NSLocalizedString(@FW_URL_PREFIX ,nil), theDocumentName];
>
> theFW_URL = [NSURL URLWithString:theURLString];
>
> //Create an NSAttributedString to hold the RTF description of
> the URL.
> theRTF_string= [[NSAttributedString alloc] initWithString:
> theURLName];
> theStringRange.location = 0;
> theStringRange.length = [theURLName length];
> theAttributesDict =
> [NSDictionary dictionaryWithObjects:[NSArray
> arrayWithObjects: theFW_URL, nil]
> forKeys: [NSArray
> arrayWithObjects:NSLinkAttributeName, nil]
> ];
> NSData* the_RTF_data = [theRTF_string RTFFromRange:
> theStringRange documentAttributes:theAttributesDict];
No, that's not right. The attributes need to be set in the attributed
string. The document attributes are something else entirely (more
specifically, they contain information about the *document*, not text
attributes which is what NSLinkAttributeName is). You probably want to
do -initWithString:attributes: rather than just -initWithString:, then
pass nil for the documentAttributes: argument.
Also, consider using -dictionaryWithObjectsAndKeys: or -
dictionaryWithObject:forKey: rather than -
dictionaryWithObjects:forKeys:. They're more efficient and involve
less typing too :-)
Kind regards,
Alastair.
p.s. Please copy the list on replies; that way others with similar
questions will be able to find the answers they need.
--
http://alastairs-place.net
| Related mails | Author | Date |
|---|---|---|
| Duncan Champney | Jan 18, 16:27 | |
| Steve Bird | Jan 18, 16:51 | |
| Alastair Houghton | Jan 18, 17:05 | |
| Alastair Houghton | Jan 18, 18:21 | |
| Alastair Houghton | Jan 19, 00:30 | |
| Duncan Champney | Jan 19, 13:59 | |
| Jonathon Mah | Jan 20, 10:49 | |
| Duncan Champney | Jan 20, 15:29 | |
| Duncan Champney | Jan 22, 21:44 | |
| glenn andreas | Jan 22, 23:46 | |
| William Bates | Jan 23, 13:22 |






Cocoa mail archive

