UIImage does not support gif animation, but you can do this via 3rd party libraries or Extensions.
You can use the extension here SwiftGif
Add the linked file to the source of playground, then run your code like this:
import UIKit
import PlaygroundSupport
let image = UIImage.gif(name: "earth.gif")
.....
PlaygroundPage.current.liveView = imageView
However for macOS NSImage can be directly showed, you can create a mac playground and write code like this to directly see the animating gif
import Cocoa
import PlaygroundSupport
let image = NSImage(named: "earth.gif")
let imageView = NSImageView(image: image!)
imageView.frame = CGRect(x: 0, y: 0, width: 200.0, height: 200.0)
PlaygroundPage.current.liveView = imageView