トピック一覧の取得
アプリケーションスコープのトピック一覧の取得
アプリケーションスコープの全てのトピックを一覧として取得することができます。トピックの件数が 50 件を超える場合は、ページネーションによって複数回にわけて一覧を取得する必要があります。
以下に、アプリケーションスコープに存在するトピックの一覧を取得する例を挙げます。
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. }]; }]; } }];
ここでは、以下の処理を実行しています。
listTopicsSynchronous
メソッドを実行し、トピック一覧を取得します。[KiiListResult results]
メソッドを実行し、トピック一覧をNSArray
で取得します。[KiiListResult hasNext]
メソッドを実行して取得しきれなかったトピックがあるか確認し、ある場合はgetPaginationKey
メソッドで取得したキーを引数に、再度listTopicsSynchronous
メソッドを実行します。
グループスコープのトピック一覧の取得
グループスコープの全てのトピックを一覧として取得することができます。トピックの件数が 50 件を超える場合は、ページネーションによって複数回にわけて一覧を取得する必要があります
以下に、グループスコープに存在するトピックの一覧を取得する例を挙げます。
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. }]; }]; } }];
ここでは、以下の処理を実行しています。
listTopicsSynchronous
メソッドを実行し、トピック一覧を取得します。[KiiListResult results]
メソッドを実行し、トピック一覧をNSArray
で取得します。[KiiListResult hasNext]
メソッドを実行して取得しきれなかったトピックがあるか確認し、ある場合はgetPaginationKey
メソッドで取得したキーを引数に、再度listTopicsSynchronous
メソッドを実行します。
ユーザースコープのトピック一覧の取得
ユーザースコープの全てのトピックを一覧として取得することができます。トピックの件数が 50 件を超える場合は、ページネーションによって複数回にわけて一覧を取得する必要があります
以下に、ユーザースコープに存在するトピックの一覧を取得する例を挙げます。
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. }]; }]; } }];
ここでは、以下の処理を実行しています。
listTopicsSynchronous
メソッドを実行し、トピック一覧を取得します。[KiiListResult results]
メソッドを実行し、トピック一覧をNSArray
で取得します。[KiiListResult hasNext]
メソッドを実行して取得しきれなかったトピックがあるか確認し、ある場合はgetPaginationKey
メソッドで取得したキーを引数に、再度listTopicsSynchronous
メソッドを実行します。