Four steps to Swift 4 export of images in Graphic 3.1


If you use Graphic on macOS for your vector drawing you might have noticed in the recent update that you can now export images to Swift 4.


There are a couple of steps to achieve this:

1.  Go to Graphic > Preferences... on the menu bar and select the Import/Export tab. At the bottom of the window you will see that there is a drop down menu under Core Graphics Export. Change the selected item from Objective-C to Swift 4 and decide whether you'd like code for display on iOS or macOS devices.


2.  Select the object(s) you wish to export in your drawing.


3.  From the top menu select Edit > Copy As > Core Graphics Code


4.  Now you can Cmd + v paste the code into your app. However, be aware that the output code is designed to be used within the draw(_ :) of a UIView subclass and that you are responsible for the surrounding code. Here the red box highlights the pasted code and the surrounding code has been written beforehand.


The surrounding code reads:
import UIKit

class View:UIView {
    override func draw(_ rect: CGRect) {
        // insert Graphic generated Swift 4 code here
    }
}

let v = View(frame: CGRect(x: 0, y: 0, width: 400, height: 100))
Change your view's frame accordingly to test the results.


Comments