How do you save the combination of an image and lines drawn on it? Swift
<p>I've got saving an image down, but whenever I draw lines on the image and try to save the image, the image doesn't save with the lines I drew on it. How do I go about saving the images with the lines drawn on it?</p>

<p>Here's the current code for drawing lines:</p>

<pre><code>import UIKit
import CoreData

class DrawClass: UIView {
    /*
    // Only override drawRect: if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func drawRect(rect: CGRect) {
        // Drawing code
    }
    */
    ///Creating an array of type Line which accepts a Line object. It is an empty array.
    var lines:[Line] = []
    var lastPoint: CGPoint!

    required init(coder aDecoder: NSCoder)
    {
        super.init(coder: aDecoder)
        self.backgroundColor = UIColor.whiteColor()
        self.layer.zPosition = 1
    }

    override func touchesBegan(touches: Set&lt;NSObject&gt;, withEvent event: UIEvent){
        if let touch = touches.first as? UITouch {
            lastPoint =  touch.locationInView(self)
        }
    }

    override func touchesMoved(touches: Set&lt;NSObject&gt;, withEvent event: UIEvent){
        if let touch = touches.first as? UITouch {
            var newPoint = touch.locationInView(self)
            lines.append(Line(start: lastPoint, end: newPoint))
            lastPoint = newPoint
        }
        self.setNeedsDisplay()
    }

    override func drawRect(rect: CGRect) {
        var context = UIGraphicsGetCurrentContext()
        CGContextBeginPath(context)
        for line in lines
        {
            CGContextMoveToPoint(context, line.start.x, line.start.y)
            CGContextAddLineToPoint(context, line.end.x, line.end.y)
        }

        var storage: Float = ViewController.simple.storage1
        var storage2: Float = ViewController.simple.storage2
        var storage3: Float = ViewController.simple.storage3

        CGContextSetRGBStrokeColor(context, CGFloat(storage), CGFloat(storage2), CGFloat(storage3), 1)

        CGContextSetLineWidth(context, 5)
        CGContextStrokePath(context)
    }
}
</code></pre>

<p><strong>UPDATE</strong>
Sorry, I forgot to add in the saving method. By the way "earth" is the name of the image I placed in the storyboard Here it is:</p>

<pre><code>@IBAction func saveImage(sender: UIButton) {


    UIImageWriteToSavedPhotosAlbum(earth.image!, self, "image:didFinishSavingWithError:contextInfo:", nil)

}

func image(image: UIImage, didFinishSavingWithError error: NSError?, contextInfo:UnsafePointer&lt;Void&gt;) {
    if error == nil {
        let ac = UIAlertController(title: "Saved!", message: "Your altered image has been saved to your photos.", preferredStyle: .Alert)
        ac.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
        presentViewController(ac, animated: true, completion: nil)
    } else {
        let ac = UIAlertController(title: "Save error", message: error?.localizedDescription, preferredStyle: .Alert)
        ac.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
        presentViewController(ac, animated: true, completion: nil)
    }
}
</code></pre>