Get NSImage from NSTextField in Swift -


i used retrieve nsimage in subclass of nstextfield obj-c this:

  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] ...   }  

when try same in swift can't seem able cast attachmentcell compiler error:

  let attributedval = attributedstringvalue.attributesatindex(i, effectiverange: effectiverange)   if let attachment = attributedval[nsattachmentattributename] as? nstextattachment {     let attachmentcell = attachment.attachmentcell nscell // not work     ...   } 

thanks nate cook. following works:

  let attributedval = attributedstringvalue.attributesatindex(i, effectiverange: effectiverange)   if let attachment = attributedval[nsattachmentattributename] as? nstextattachment {     let attachmentcell = attachment.attachmentcell nstextattachmentcell     let image = attachmentcell.image     ...   } 

Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -