title: Convert SVG Node (Macaw) to NSImage Swift4 / Cocoa
body: <p>I'm trying to convert from a Macaw SVG (Node) into an NSImage.  I was able to find sample code for IOS on the Macaw forum but not able to make it work in Cocoa.  </p>
  
  <p>There are references in the Macaw libraries for all the missing functions (UIGraphicsBeginImageContext, etc) as MGraphicsBeginImageContext but have not been able to access them yet (Use of unresolved identifier 'UIGraphicsBeginImageContext') </p>
  
  <p>Here's the sample code from the original article <a href="https://github.com/exyte/Macaw/pull/382#issuecomment-393422770" rel="nofollow noreferrer">https://github.com/exyte/Macaw/pull/382#issuecomment-393422770</a></p>
  
  <pre><code>func svgToImge(resourceName: String, size: CGSize) -&gt; NSImage {
          if let rootNode = try? SVGParser.parse(path: resourceName)
          {
              let macawView = MacawView(node: rootNode, frame:CGRect(origin: CGPoint.zero, size: size))
              UIGraphicsBeginImageContext(size)
              macawView.layer.render(in: UIGraphicsGetCurrentContext()!)
              let img =  UIGraphicsGetImageFromCurrentImageContext();
              UIGraphicsEndImageContext();
              return img!
          } else {
              return NSImage()
          }
      }
  </code></pre>