RiveViewModel manages the runtime. triggerInput and setBooleanInput drive the state machine animations.
In Xcode: File → Add Package Dependencies. Paste the URL below.
Drag your .riv file into Xcode (check 'Copy items if needed'), then create a RiveViewModel with the file name and state machine.
import RiveRuntime
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let riveModel = RiveViewModel(
fileName: "your_animation",
stateMachineName: "State Machine 1"
)
let riveView = riveModel.createRiveView()
riveView.frame = CGRect(x: 100, y: 100, width: 150, height: 150)
view.addSubview(riveView)
}
}Trigger the Hover and Clicked animations included in every Unicorn Icon.
// Fire a trigger input (one-shot animation)
riveModel.triggerInput("Clicked")
// Set a boolean input (hold state)
riveModel.setBooleanInput("Hover", value: true) // hover start
riveModel.setBooleanInput("Hover", value: false) // hover end
// Read a value
let isActive = riveModel.getBooleanInput("IsActive")Does this work with SwiftUI?
Yes. Use RiveViewModel as @ObservedObject and call riveModel.createRiveView(). Rive has native SwiftUI support.
How do I add the .riv file?
Drag it into the project navigator with "Copy items if needed" checked. Reference it by name without the .riv extension.
What inputs do Unicorn Icons include?
All icons have a state machine called State Machine 1 with boolean input Hover and trigger Clicked.
Get your animated icons
Browse icons ready for iOS — free to download.