Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access UI properties from background thread in project 9 #77

Open
at1993 opened this issue Jun 8, 2022 · 0 comments
Open

Access UI properties from background thread in project 9 #77

at1993 opened this issue Jun 8, 2022 · 0 comments

Comments

@at1993
Copy link

at1993 commented Jun 8, 2022

Hi All,

I thought you are not supposed to access/change UI. However I've noticed in this sample, fetchJSON is executed in the background thread but is reading UI property navigationController?.tabBarItem.tag. Am I missing something?

@objc func fetchJSON() {
let urlString: String
if navigationController?.tabBarItem.tag == 0 {
urlString = "https://api.whitehouse.gov/v1/petitions.json?limit=100"
} else {
urlString = "https://api.whitehouse.gov/v1/petitions.json?signatureCountFloor=10000&limit=100"
}
if let url = URL(string: urlString) {
if let data = try? Data(contentsOf: url) {
parse(json: data)
return
}
}
performSelector(onMainThread: #selector(showError), with: nil, waitUntilDone: false)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant