Skip to main content

Manage tag data

This guide explains how to create and manage tag data with the NCEngine APIs. The Chat SDK supports tags (NCTag) for grouping channels. Each user can create up to 20 tags, and tag data syncs to the server automatically.

NCTag properties:

PropertyTypeDescription
tagIdNSStringUnique tag identifier (max 10 characters)
tagNameNSStringTag name (max 15 characters, duplicates allowed)
countNSIntegerNumber of channels under this tag
timestamplong longTimestamp provided by the SDK
tip

This guide covers tag data management only. For tagging channels and querying tagged channel data, see Tag channels.

Create a tag

Each user can create up to 20 tags:

swift
import NexconnChatSDK
let params = CreateTagParams(tagId: "tagId", tagName: "tagName")
Tag.createTag(params: params) { tag, error in
if let tag, error == nil {
print("Tag created: \(tag.tagName) (\(tag.tagId))")
} else {
print("Failed to create tag: \(error?.localizedDescription ?? "unknown error")")
}
}

Remove a tag

Call deleteWithCompletion: on a tag instance:

swift
import NexconnChatSDK
let tag: Tag? = nil // Replace with a Tag instance from Tag.getTag/getTags
guard let tag else { return }
tag.delete { error in
if error == nil {
print("Tag removed")
}
}

Update a tag

You can only update the tagName field (max 15 characters, duplicates allowed):

swift
import NexconnChatSDK
let tag: Tag? = nil // Replace with a Tag instance from Tag.getTag/getTags
guard let tag else { return }
tag.update(tagName: "New Tag Name") { error in
if error == nil {
print("Tag name updated: \(tag.tagName)")
}
}

Get all tags

swift
import NexconnChatSDK
Tag.getTags { tags, error in
if error == nil {
for tag in tags ?? [] {
print("Tag: \(tag.tagName) (ID: \(tag.tagId), Count: \(tag.count))")
}
}
}

Multi-device tag sync

The SDK supports multi-device login. When a user changes tags on one device, the SDK notifies the user's other devices. After you receive the notification, call getTagsWithCompletion: to fetch the latest tag data.

tip
  • Register the delegate after initialization but before connecting.
  • Local modifications do not trigger the callback — only changes from other devices do.

Register the delegate

swift
import NexconnChatSDK
final class MyTagHandler: NSObject, TagHandler {}
let tagHandler = MyTagHandler()
NCEngine.addTagHandler(identifier: "MyTagHandler", handler: tagHandler)

Handle the callback

swift
import NexconnChatSDK
func onTagChanged(_ event: TagChangedEvent) {
// Fetch the latest tag list from the server
Tag.getTags { tags, error in
// Update UI
}
}