unarchiveObject(with:) deprecated

605 Views Asked by At

As part of an extension to draw an outer stroke of a text in an UILabel, I came up with a solution that consists in:

  1. duplicating the original UILabel without the stroke
  2. apply the outer stroke on the original label

It works fine.

However I am not satisfied with my code to create a copy of the UILabel, especially since part of it does not recuperate any potential error whilst the rest uses a deprecated code.

extension UILabel {    
func createCopy() -> UILabel {

        let archivedLabel       = try? NSKeyedArchiver.archivedData(withRootObject: self, requiringSecureCoding: false)
        return NSKeyedUnarchiver.unarchiveObject(with: archivedLabel!) as! UILabel
    }
}

I don't recuperate a potential error NSKeyedArchiver and NSKeyedUnarchiver.UnarchiObject(with:) is deprecated. I am supposed to use unarchivedObjectOfClass:fromData:error: but I can't seem to make it work.

I'd be very thankful for any tips that can improve it!

Best,

Chris

0

There are 0 best solutions below