I want to save image with userdefaults and use it in another view with this code but it shows an error .
UserDefaults.standard.set(img , forKey : \"simg\")
As others have said, don't save images to user defaults. It's only intended for small bits of data.
If all you want to do is to pass an image in another view controller, and you don't care about making the image persist if the user quits and re-launches the app, just pass the image in prepareForSegue
.