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

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -