title: save image view as binary data in Core Data (swift4)
body: <p>I am trying to save a image view to binary data. The code compiles but when the button is pressed a sigabbt error occurs. The image view has a image in it. I don't know what is going on. Its just the image view is not saving. </p>
  
  <pre><code>  class editVCViewController: UIViewController {
      @IBOutlet var imageV: UIImageView!
      @IBOutlet var theView: UIView!
      @IBOutlet var mattBarnes: UITextField!
      @IBAction func magicJohnson(_ sender: Any) {
  
          let photo = self.imageV.image
          let data = UIImagePNGRepresentation(photo!)
  
              if cdHandler.saveObject(pic:  data!){
  
            }}
  
  }
  
  
  
  
          class func saveObject(pic: Data) -&gt; Bool {
          let context = getContext()
          let entity = NSEntityDescription.entity(forEntityName: "User", in: context)
  
          let managedObject = NSManagedObject(entity: entity!, insertInto: context)
          managedObject.setValue(pic, forKey:"binaryAttribute")
  
          do {
              try context.save()
              return true
  
          } catch {
              return false
  
          }
      }
  </code></pre>