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:
| Property | Type | Description |
|---|---|---|
| tagId | NSString | Unique tag identifier (max 10 characters) |
| tagName | NSString | Tag name (max 15 characters, duplicates allowed) |
| count | NSInteger | Number of channels under this tag |
| timestamp | long long | Timestamp 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
- Objective-C
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")")
}
}
Objective C
NCCreateTagParams *params = [[NCCreateTagParams alloc] initWithTagId:@"tagId" tagName:@"tagName"];
[NCTag createTagWithParams:params completion:^(NCTag * _Nullable tag, NCError * _Nullable error) {
if (error == nil && tag) {
NSLog(@"Tag created: %@ (%@)", tag.tagName, tag.tagId);
} else {
NSLog(@"Failed to create tag: %@", error);
}
}];
Remove a tag
Call deleteWithCompletion: on a tag instance:
- Swift
- Objective-C
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")
}
}
Objective C
[tag deleteWithCompletion:^(NCError * _Nullable error) {
if (error == nil) {
NSLog(@"Tag removed");
}
}];
Update a tag
You can only update the tagName field (max 15 characters, duplicates allowed):
- Swift
- Objective-C
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)")
}
}
Objective C
[tag updateTagName:@"New Tag Name" completion:^(NCError * _Nullable error) {
if (error == nil) {
NSLog(@"Tag name updated: %@", tag.tagName);
}
}];
Get all tags
- Swift
- Objective-C
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))")
}
}
}
Objective C
[NCTag getTagsWithCompletion:^(NSArray<NCTag *> * _Nullable tags, NCError * _Nullable error) {
if (error == nil) {
for (NCTag *tag in tags) {
NSLog(@"Tag: %@ (ID: %@, Count: %d)", tag.tagName, tag.tagId, 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
- Objective-C
swift
import NexconnChatSDK
final class MyTagHandler: NSObject, TagHandler {}
let tagHandler = MyTagHandler()
NCEngine.addTagHandler(identifier: "MyTagHandler", handler: tagHandler)
Objective C
[NCEngine addTagHandlerWithIdentifier:@"MyTagHandler" handler:self];
Handle the callback
- Swift
- Objective-C
swift
import NexconnChatSDK
func onTagChanged(_ event: TagChangedEvent) {
// Fetch the latest tag list from the server
Tag.getTags { tags, error in
// Update UI
}
}
Objective C
- (void)onTagChanged {
// Fetch the latest tag list from the server
[NCTag getTagsWithCompletion:^(NSArray<NCTag *> * _Nullable tags, NCError * _Nullable error) {
// Update UI
}];
}