Skip to main content

Choosing an Artboard

When a Rive object is instantiated or when a Rive file is rendered, you can specify the artboard to use. If no artboard is given, the default artboard, as set in the Rive editor, is used. If no default artboard is set, the first artboard is used. Only one artboard can be rendered at a time.
The following section assumes that you have read through the Apple overview.

Getting an Artboard

Once you have created a File, you can then retrieve information for and create Artboard types.
// Get all artboard names in the file
let artboardNames = try await file.getArtboardNames()
// Get the default artboard for the file
let defaultArtboard = try await file.createArtboard()
// Get an artboard by name from the file
let artboardByName = try await file.createArtboard("Artboard")
Note that these are all async throwing functions marked as @MainActor. Since they are functions called on a File object, any thrown errors will be of type FileError.An example of when one of these functions will throw is if you call .createArtboard(_:) with a name that is not in the origin File, which will throw a FileError.invalidArtboard(String).

Using an Artboard

Remember that the Rive configuration for a view is the Rive type. In the overview, we show initializing a Rive object with a file, opting to use the default artboard and state machine. However, you can initialize a Rive object with a specific artboard:
let worker = Worker()
let file = try await File(source: .local("my_file", Bundle.main))
let artboardByName = try await file.createArtboard("Artboard")
let rive = try await Rive(file: file, artboard: artboardByName)
Artboards then become the source of truth for state machines. See State Machine for more details.