The following sample code shows how to create a group.
The basic steps for group creation are as follows:
Create a KiiGroup instance with the KiiGroup(name:) method.
Register this KiiGroup instance with the save(_:) method.
The group name can be up to 190 characters. There is no restriction on the characters you can use. The group name can duplicate with the existing ones. You cannot retrieve (reinstantiate) the existing group with its name; the group name is merely for debugging and displaying purposes.
After you create a group, you can get its URI and ID by executing the objectURI() and groupID() methods. You can use them to retrieve the group later.
Creating a group with members
When you create a new group, you can also set its group members at the same time.
In the previous sample code, the group ID is automatically assigned. You can also specify the group ID explicitly when you create the group.
The next sample is creating a new group, this time with its ID.
We use the register(withID:name:members:_:) method for creating a group with its group ID. The group ID can contain alphanumeric (lower-case only), period (.), dash (-), and underscore (_). The maximum length of the group ID is 30 characters. You will get an error if you try to set a group ID that duplicates with the existing one.
In the above sample code, we are concatenating a unique value which represents a user with the prefix "my-group-" and using it as the group ID. This will allow spotting IDs of groups owned by a certain user. This naming method is useful, for instance, if you are managing Twitter-like followers with the group feature. The above sample code assumes that a short unique value such as a sequence number has been configured as a custom attribute. You cannot use the user ID as a part of the group ID because it would exceed the maximum length of 30 characters for the group ID.
You can also set the group members at the same time. Set the group members in the third argument of the register(withID:name:members:_:) method.