2
я использовал для получения NSImage в подклассе NSTextField от Obj-C, как это:Получить NSImage от NSTextField в Swift
NSDictionary *attributedVal = [[self attributedStringValue] attributesAtIndex:i effectiveRange:&effectiveRange];
if ([[attributedVal allKeys] containsObject:NSAttachmentAttributeName]) {
NSTextAttachment *attachment = [attributedVal valueForKey:NSAttachmentAttributeName];
NSCell *attachmentCell = (NSCell *)[attachment attachmentCell];
... [[attachmentCell image] name] ...
}
Когда я пытаюсь сделать то же самое в Swift я не могу быть возможно получить коммандер
let attributedVal = attributedStringValue.attributesAtIndex(i, effectiveRange: effectiveRange)
if let attachment = attributedVal[NSAttachmentAttributeName] as? NSTextAttachment {
let attachmentCell = attachment.attachmentCell as NSCell // does not work
...
}
Можете ли вы наложить на 'NSTextAttachmentCell' вместо этого? 'attachment.attachmentCell' имеет тип' NSTextAttachmentCellProtocol' в Swift, который 'NSCell' не соответствует, но' NSTextAttachmentCell' делает. –