Wallpapers aren't animated so you can really "code" a wall paper (other than by setting an image). But you can write a screen saver using Metal.
I'm actually not very familiar with the screen saver API from the ScreenSaver.framework. Questions related to that are probalby better asked in the AppKit forum. I'm also more familiar with the ObjC APIs than Swift. But I'll try to give you some info on the Metal parts.
You can start by creating a 'Screen Saver' project in xcode. You'll need to implement the view provided to you in that project. Since that view needs to inherit from ScreenSaverView, you won't be albe to use MTKView for rendering. Instead, you'll need to return CAMetalLayer in your view's layerClass. This will enable to get Metal drawables from the view's layer. Then you can set up a RenderPassDescriptor with that drawable's texture and render to the drawablew which should show up on the screen once you present that drawable.