Getting a List of Topics

Getting a list of application-scope topics

You can get a list of all application scope topic. If there are more than 50 topics, you need to get the topic list in multiple pages with the pagination.

The following is the sample code for getting a list of all application scope topics.

Swift:

  • var resultObj : KiiListResult
    
    do{
      // Get the first page of the topic list.
      resultObj = try Kii.listTopicsSynchronous()
    }catch(let error as NSError){
      // Handle the error.
      return
    }
    for topic in (resultObj.results as! [KiiTopic]){
      // Do something.
    }
    
    if resultObj.hasNext {
      // Get the next page of the topic list.
      resultObj = try! Kii.listTopicsSynchronous(resultObj.paginationKey!, error: ())
      for topic in (resultObj.results as! [KiiTopic]){
        // Do something.
      }
    }
  • // Get the first page of the topic list.
    Kii.listTopics { (resultObj : KiiListResult?, callerObject : Any?, error : Error?) -> Void in
      if error != nil {
        // Handle the error.
        return
      }
      for topic in (resultObj!.results as! [KiiTopic]){
        // Do something.
      }
    
      if resultObj!.hasNext {
        // Get the next page of the topic list.
        Kii.listTopics((resultObj!.paginationKey)!, block: { (resultObj : KiiListResult?, callerObject : Any?, error : Error?) -> Void in
          if error != nil {
            // Handle the error.
            return
          }
          for topic in (resultObj!.results as! [KiiTopic]){
            // Do something.
          }
        })
      }
    }

Objective-C:

  • NSError* error = nil;
    
    // Get the first page of the topic list.
    KiiListResult *resultObj = [Kii listTopicsSynchronous:&error];
    if(error){
      // Handle the error.
      return;
    }
    [resultObj.results enumerateObjectsUsingBlock:^(KiiTopic* topic, NSUInteger idx, BOOL *stop) {
      // Do something.
    }];
    
    if(resultObj.hasNext){
      // Get the next page of the topic list.
      resultObj = [Kii listTopicsSynchronous:resultObj.paginationKey error:&error];
      [resultObj.results enumerateObjectsUsingBlock:^(KiiTopic* topic, NSUInteger idx, BOOL *stop) {
        // Do something.
      }];
    }
  • // Get the first page of the topic list.
    [Kii listTopics:^(KiiListResult *resultObj, id callerObject, NSError *error) {
      if(error){
        // Handle the error.
        return;
      }
      [resultObj.results enumerateObjectsUsingBlock:^(KiiTopic* topic, NSUInteger idx, BOOL *stop) {
        // Do something.
      }];
    
      if(resultObj.hasNext){
        // Get the next page of the topic list.
        [Kii listTopics:^(KiiListResult *resultObj, id callerObject, NSError *error) {
          [resultObj.results enumerateObjectsUsingBlock:^(KiiTopic* topic, NSUInteger idx, BOOL *stop) {
            // Do something.
          }];
        }];
      }
    }];

This is the brief explanation of the sample code:

  • Execute the listTopicsSynchronous method to get a list of topics.
  • Execute the [KiiListResult results] method to get the topic list as a NSArray.
  • Execute the [KiiListResult hasNext] method to check if there exist more topics to get. If there are ones, execute the getPaginationKey to get a key and execute the listTopicsSynchronous again with this key.

Getting a list of group-scope topics

You can get a list of all topics in the specified group scope. If there are more than 50 topics, you need to get the topic list in multiple pages with the pagination.

The following is the sample code for getting a list of all topics in a group scope.

Swift:

  • // Instantiate an existing group.
    let aGroup = KiiGroup(id: "groupID")
    var resultObj : KiiListResult
    
    do{
      // Get the first page of the topic list.
      resultObj = try aGroup.listTopicsSynchronous()
    }catch(let error as NSError){
      // Handle the error.
      return
    }
    for topic in (resultObj.results as! [KiiTopic]){
      // Do something.
    }
    
    if resultObj.hasNext {
      // Get the next page of the topic list.
      resultObj = try! Kii.listTopicsSynchronous(resultObj.paginationKey!, error: ())
      for topic in (resultObj.results as! [KiiTopic]){
        // Do something.
      }
    }
  • // Instantiate an existing group.
    let aGroup = KiiGroup(id: "groupID")
    
    // Get the first page of the topic list.
    aGroup.listTopics { (resultObj : KiiListResult?, callerObject : Any?, error : Error?) -> Void in
      if error != nil {
        // Handle the error.
        return
      }
      for topic in (resultObj!.results as! [KiiTopic]){
        // Do something.
      }
    
      if resultObj!.hasNext {
        // Get the next page of the topic list.
        aGroup.listTopics(resultObj!.paginationKey, block: { (resultObj : KiiListResult?, callerObject : Any?, error : Error?) -> Void in
          if error != nil {
            // Handle the error.
            return
          }
          for topic in (resultObj!.results as! [KiiTopic]){
            // Do something.
          }
        })
      }
    }

Objective-C:

  • NSError* error = nil;
    
    // Instantiate an existing group.
    KiiGroup *aGroup = [KiiGroup groupWithID:@"groupID"];
    
    // Get the first page of the topic list.
    KiiListResult *resultObj = [aGroup listTopicsSynchronous:&error];
    if(error){
      // Handle the error.
      return;
    }
    [resultObj.results enumerateObjectsUsingBlock:^(KiiTopic* topic, NSUInteger idx, BOOL *stop) {
      // Do something.
    }];
    
    if(resultObj.hasNext){
      // Get the next page of the topic list.
      resultObj = [aGroup listTopicsSynchronous:resultObj.paginationKey error:&error];
      [resultObj.results enumerateObjectsUsingBlock:^(KiiTopic* topic, NSUInteger idx, BOOL *stop) {
        // Do something.
      }];
    }
  • // Instantiate an existing group.
    KiiGroup *aGroup = [KiiGroup groupWithID:@"groupID"];
    
    // Get the first page of the topic list.
    [aGroup listTopics:^(KiiListResult *resultObj, id callerObject, NSError *error) {
      if(error){
        // Handle the error.
        return;
      }
      [resultObj.results enumerateObjectsUsingBlock:^(KiiTopic* topic, NSUInteger idx, BOOL *stop) {
        // Do something.
      }];
    
      if(resultObj.hasNext){
        // Get the next page of the topic list.
        [aGroup listTopics:^(KiiListResult *resultObj, id callerObject, NSError *error) {
          [resultObj.results enumerateObjectsUsingBlock:^(KiiTopic* topic, NSUInteger idx, BOOL *stop) {
            // Do something.
          }];
        }];
      }
    }];

This is the brief explanation of the sample code:

  • Execute the listTopicsSynchronous method to get a list of topics.
  • Execute the [KiiListResult results] method to get the topic list as a NSArray.
  • Execute the [KiiListResult hasNext] method to check if there exist more topics to get. If there are ones, execute the getPaginationKey to get a key and execute the listTopicsSynchronous again with this key.

Getting a list of user-scope topics

You can get a list of all topics in the specified user scope. If there are more than 50 topics, you need to get the topic list in multiple pages with the pagination.

The following is the sample code for getting a list of all topics in a user scope.

Swift:

  • // Get the currently logged-in user.
    let aUser = KiiUser(id: "UserID")
    var resultObj : KiiListResult
    
    do{
      // Get the first page of the topic list.
      resultObj = try aUser.listTopicsSynchronous()
    }catch(let error as NSError){
      // Handle the error.
      return
    }
    for topic in (resultObj.results as! [KiiTopic]){
      // Do something.
    }
    
    if resultObj.hasNext {
      // Get the next page of the topic list.
      resultObj = try! Kii.listTopicsSynchronous(resultObj.paginationKey!, error: ())
      for topic in (resultObj.results as! [KiiTopic]){
        // Do something.
      }
    }
  • // Get the currently logged-in user.
    let aUser = KiiUser.current()!
    
    // Get the first page of the topic list.
    aUser.listTopics { (resultObj : KiiListResult?, callerObject : Any?, error : Error?) -> Void in
      if error != nil {
        // Handle the error.
        return
      }
      for topic in (resultObj!.results as! [KiiTopic]){
        // Do something.
      }
    
      if resultObj!.hasNext {
        // Get the next page of the topic list.
        aUser.listTopics(resultObj!.paginationKey, block: { (resultObj : KiiListResult?, callerObject : Any?, error : Error?) -> Void in
          if error != nil {
            // Handle the error.
            return
          }
          for topic in (resultObj!.results as! [KiiTopic]){
            // Do something.
          }
        })
      }
    }

Objective-C:

  • NSError* error = nil;
    
    // Get the currently logged-in user.
    KiiUser *aUser = [KiiUser currentUser];
    
    // Get the first page of the topic list.
    KiiListResult *resultObj = [aUser listTopicsSynchronous:&error];
    if(error){
      // Handle the error.
      return;
    }
    [resultObj.results enumerateObjectsUsingBlock:^(KiiTopic* topic, NSUInteger idx, BOOL *stop) {
      // Do something.
    }];
    
    if(resultObj.hasNext){
      // Get the next page of the topic list.
      resultObj = [aUser listTopicsSynchronous:resultObj.paginationKey error:&error];
      [resultObj.results enumerateObjectsUsingBlock:^(KiiTopic* topic, NSUInteger idx, BOOL *stop) {
        // Do something.
      }];
    }
  • // Get the currently logged-in user.
    KiiUser *aUser = [KiiUser currentUser];
    
    // Get the first page of the topic list.
    [aUser listTopics:^(KiiListResult *resultObj, id callerObject, NSError *error) {
      if(error){
        // Handle the error.
        return;
      }
      [resultObj.results enumerateObjectsUsingBlock:^(KiiTopic* topic, NSUInteger idx, BOOL *stop) {
        // Do something.
      }];
    
      if(resultObj.hasNext){
        // Get the next page of the topic list.
        [aUser listTopics:^(KiiListResult *resultObj, id callerObject, NSError *error) {
          [resultObj.results enumerateObjectsUsingBlock:^(KiiTopic* topic, NSUInteger idx, BOOL *stop) {
            // Do something.
          }];
        }];
      }
    }];

This is the brief explanation of the sample code:

  • Execute the listTopicsSynchronous method to get a list of topics.
  • Execute the [KiiListResult results] method to get the topic list as a NSArray.
  • Execute the [KiiListResult hasNext] method to check if there exist more topics to get. If there are ones, execute the getPaginationKey to get a key and execute the listTopicsSynchronous again with this key.