# How to save a imageview as binary data in Swift 5

**URL:** <https://forums.kodeco.com/t/how-to-save-a-imageview-as-binary-data-in-swift-5/74327>\
**Category:** Swift\
**Created:** [June 20, 2019, 4:39am UTC](https://forums.kodeco.com/t/how-to-save-a-imageview-as-binary-data-in-swift-5/74327 "2019-06-20T04:39:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![timswift](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/timswift/32/110937_2.png) [@timswift](https://forums.kodeco.com/u/timswift)\
**Post date:** [June 20, 2019, 4:39am UTC](https://forums.kodeco.com/t/how-to-save-a-imageview-as-binary-data-in-swift-5/74327/1 "2019-06-20T04:39:49Z")

</div>

I am trying to save the imageview to core data as a binary data. In my function I have already saved a string and it works perfectly. However when I try to do the exact same thing with (theTitle2) it does not work. I also have class cdhandler in my question below which is what is saved in app deleagate.I think what I have to do is somehow convert the image view to a uiimage then save it.

```
                      func enterData() {

```

let appDeldeaget = UIApplication.shared.delegate as! AppDelegate  
let context = appDeldeaget.persistentContainer.viewContext  
let entity = NSEntityDescription.entity(forEntityName: “User”, in: context)  
let theTitle = NSManagedObject(entity: entity!, insertInto: context)  
theTitle.setValue(enter.text, forKey: “userName”)  
let theTitle2 = NSManagedObject(entity: entity!, insertInto: context)  
theTitle2.setValue(imageV.image, forKey: “pit”)

do {

```
try context.save()
itemName.append(theTitle)

       }
        catch { }
   //

      }

```

APP DELEGATE

```
                class cdHandler: NSObject {

```

class func saveObject(userName: String) → Bool {  
let context = getContext()  
let entity = NSEntityDescription.entity(forEntityName: “User”, in: context)

```
let managedObject = NSManagedObject(entity: entity!, insertInto: context)

managedObject.setValue(userName, forKey: "userName")
managedObject.setValue(userName, forKey: "pit")

do {
    try context.save()
    return true

} catch {
    return false

}

```

}  
}

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [July 9, 2019, 8:31pm UTC](https://forums.kodeco.com/t/how-to-save-a-imageview-as-binary-data-in-swift-5/74327/2 "2019-07-09T20:31:13Z")

</div>

@timswift Do you still have issues with this?

---

<div class="post-metadata">

**Author:** ![timswift](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/timswift/32/110937_2.png) [@timswift](https://forums.kodeco.com/u/timswift)\
**Post date:** [July 10, 2019, 1:25pm UTC](https://forums.kodeco.com/t/how-to-save-a-imageview-as-binary-data-in-swift-5/74327/3 "2019-07-10T13:25:47Z")

</div>

No this issue has been resolved thanks for looking at it.

---

<div class="post-metadata">

**Author:** ![system](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@system](https://forums.kodeco.com/u/system)\
**Post date:** [December 3, 2019, 8:39pm UTC](https://forums.kodeco.com/t/how-to-save-a-imageview-as-binary-data-in-swift-5/74327/4 "2019-12-03T20:39:52Z")

</div>

This topic was automatically closed after 166 days. New replies are no longer allowed.
