Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

StackOverflow Point

StackOverflow Point Navigation

  • Web Stories
  • Badges
  • Tags
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Web Stories
  • Badges
  • Tags
Home/ Questions/Q 4291
Alex Hales
  • 0
Alex HalesTeacher
Asked: June 3, 20222022-06-03T16:34:43+00:00 2022-06-03T16:34:43+00:00

asynchronous – Swift MacOS making async calls in for loop…how can I tell when they are completed?

  • 0

[ad_1]

Background I am building a desktop app that will enable me to aggregate some analytics for Confluence pages.

To do this you call the Atlassian Confluence API and get all pages for a space. The way we have the space set up we use labels and we have a “no-analytics” label which allows us to filter out landing pages or other pages we’ve no interest in getting analytics from.

To get the labels you need to get the page id then make a separate API call using the id and label endpoint. This is where I am getting stuck, I get all the page ids, dump them into an array, loop through the array and make the API call. Check the results and see if any of the labels contain “no-analytics”, if not I filter those ids into a new array that I can then use to make the analytic calls.

So the problem is I can’t tell when the API calls are complete and the new array has all the ids. Here’s my code. Open to any suggestions to make this more efficient and, well, work. : D

@objc func getKTCLabels(notification:NSNotification) {
        
        var arrPagesToAnalyze:Array<String> = []
        
        if let dictData = notification.userInfo as? Dictionary<String, Any>, let arrIds = dictData["ids"] as? Array<String> {
            
            for thisId in arrIds {
                
                //get the labels for this page
                let strURL = myAppManager.formatURL(["id":thisId], 2)
                    
                myAppManager.callAPI(strURL, .confluence, completed: {(dictResults:Dictionary<String, Any>) in
                    if let arrData = dictResults["data"] as? Array<Dictionary<String, Any>> {
                        if arrData.count > 0 {
                            var bNoAnalytics = false
                            for dictLabel in arrData {
                                if let strLabel = dictLabel["label"] as? String {
                                    if strLabel == "no-analytics" {
                                        bNoAnalytics = true
                                        break
                                    }
                                }
                            }
                            
                            if !bNoAnalytics {
                                arrPagesToAnalyze.append(thisId)
                            }
                            
                        } else {
                            print(strURL) //page url without labels
                        }
                    }
                })
                
            }//end loop
        }
    }

[ad_2]

  • 0 0 Answers
  • 6 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report
Leave an answer

Leave an answer
Cancel reply

Browse

Sidebar

Ask A Question

Related Questions

  • xcode - Can you build dynamic libraries for iOS and ...

    • 0 Answers
  • bash - How to check if a process id (PID) ...

    • 8087 Answers
  • database - Oracle: Changing VARCHAR2 column to CLOB

    • 1871 Answers
  • What's the difference between HEAD, working tree and index, in ...

    • 1957 Answers
  • Amazon EC2 Free tier - how many instances can I ...

    • 0 Answers

Stats

  • Questions : 43k

Subscribe

Login

Forgot Password?

Footer

Follow

© 2022 Stackoverflow Point. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.