<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "visionOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "GroupActivities",
  "identifier" : "/documentation/GroupActivities/SystemCoordinator/assignRole(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Group Activities"
    ],
    "preciseIdentifier" : "s:15GroupActivities17SystemCoordinatorC10assignRoleyyxAA015SpatialTemplateF0RzlF"
  },
  "title" : "assignRole(_:)"
}
-->

# assignRole(_:)

Assigns the given spatial template role to the local participant.

```
final func assignRole(_ role: some SpatialTemplateRole)
```

## Discussion

For example, in a table tennis game with two teams you might have the following:

```swift
switch selectedTeam {
case .blue:
    systemCoordinator.assignRole(TableTennisTemplate.Role.blueTeam)
case .red:
    systemCoordinator.assignRole(TableTennisTemplate.Role.redTeam)
}
```

Note that assigning a given role does not guarantee that the
participant will be placed in a *seat* with that role. If more
participants are assigned a role than there are seats for that role,
the participant may be placed in a non-roled seat instead.
In most cases, your app should try to avoid allowing for that scenario.

> Warning: You should only assign roles that exist in the current spatial template.
> 
> This method will emit a runtime warning if the given role is not assigned
> to a seat in the current
> ``doc://com.apple.GroupActivities/documentation/GroupActivities/SystemCoordinator/Configuration-swift.struct/spatialTemplatePreference``.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)