I have an NSTextView. I insert an image into it and see it. When I get an NSTextAttachment for an NSAttributedString text view, this file wrapper is zero. How to get image data that was inserted into a text view?
I use the category in NSAttributedString to get text attachments. I would prefer not to burn to disk if possible.
- (NSArray *)allAttachments { NSError *error = NULL; NSMutableArray *theAttachments = [NSMutableArray array]; NSRange theStringRange = NSMakeRange(0, [self length]); if (theStringRange.length > 0) { NSUInteger N = 0; do { NSRange theEffectiveRange; NSDictionary *theAttributes = [self attributesAtIndex:N longestEffectiveRange:&theEffectiveRange inRange:theStringRange]; NSTextAttachment *theAttachment = [theAttributes objectForKey:NSAttachmentAttributeName]; if (theAttachment != NULL){ NSLog(@"filewrapper: %@", theAttachment.fileWrapper); [theAttachments addObject:theAttachment]; } N = theEffectiveRange.location + theEffectiveRange.length; } while (N < theStringRange.length); } return(theAttachments); }
cocoa nsattributedstring
joels
source share