How to insert an image in a text view ?

I need to display pictures in my text view…
The best example to start looking for this functionnality is the TextEdit source code on your hard disk.
Image can be inserted in text view only if rich text is enabled with
[myTextView setRichText:YES].
Inserting an image in a text view is done by inserting an attributed string describing a file attachment.
This means the image must first be wrapped in a NSFileWrapper. Example if the file is on disk:

NSFileWrapper *myFileWrapper = [[[NSFileWrapper alloc] initWithPath:
myFilePath] autorelease];
NSTextAttachement *myTextAtt = [[[NSTextAttachement alloc] initWithFileWrapper:myFileWrapper] autorelease] ;
NSAttributeString *myAttStr = [NSAttributedString attributedStringWithAttachement:myTextAtt];
Then the attributed string may be inserted in the view as usual:
[[
myTextView textStorage] beginEditing];
[[
myTextView textStorage] appendAttributedString:myAttStr];
[[
myTextView textStorage] endEditing];