My class contains an UIImage property which I want to enforce as a \'copy\' property by any external clients accessing it. But, when I try to do a copy in my custom setter,
Code for Swift 5.1:
let imageToCopy = <# your_image #> UIGraphicsBeginImageContext(imageToCopy.size) imageToCopy.draw(in: CGRect(x: 0, y: 0, width: imageToCopy.size.width, height: imageToCopy.size.height)) let copiedImage = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext()