I found this bit of code online to add a gradient to my project and it does add the gradient beautifully
let gradientLayer = CAGradientLayer()
gradientLayer.frame = self.view.bounds
gradientLayer.colors = [UIColor.systemBackground.cgColor, UIColor.systemGray2.cgColor]
self.view.layer.insertSublayer(gradientLayer, at: 0)
However, the colors don't change when I change between dark and light mode. I'm not sure why this is happening since I am using dark mode compatible colors. If anyone knows how to fix that bug please let me know.