将图像视图保存为Core Data中的二进制数据(swift4)

时间:2018-02-08 16:12:19

标签: ios core-data imageview swift4 binary-data

我正在尝试将图像视图保存为二进制数据。代码编译但按下按钮时会发生sigabbt错误。图像视图中包含图像。我不知道发生了什么事。它只是图像视图不保存。

  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) -> 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

        }
    }

0 个答案:

没有答案