Creating falling snow in the scene
Making snow fall within your app really makes it come alive: it gives a rather magical look to it and sets the right mood for our winter scene. To do this, we need to utilize the power of UIKit and the UIViewRepresentable
protocol, along with the CAEmitter
class.
Note
As you continue through the rest of this chapter, don’t worry if some of the UIKit classes and methods look different or unfamiliar to you as compared to the SwiftUI classes and methods we’ve been using. That’s because they are different, and that’s for a whole different book if you’d like to learn about UIKit. However, moving forward in this chapter, I will explain the different UIKit properties and methods used to make the snow for our animation, so you can get familiar with the process.
Adding the UIViewRepresentable protocol
The UIViewRepresentable
protocol is what’s called a wrapper for UIKit. It allows SwiftUI to work with...