|
Hi guys, Maybe you can help me with this. Even though I followed the tutorial for multi-threading very carefully, I still have couple of errors. To break this down, I want to show you the code first:
There are 2 errors for this code:
As for the 2nd part of code:
The error here says: "UITableViewController.tableView must be used from main thread only" Any hints on what I am doing wrong here? I followed Paul's tutorial step by step and these lines still appear. |
|
My guess is that this checker is just confused because you are using this from the main thread with the |
|
Hold on. According to the tutorial, fetchJSON() runs in the background, so the use of performSelector(onMainThread: seems fine here. However, the errors still persist... I'm confused. |
|
|
|
|
|
I went through multiple Reddit threads on this matter, it seems that for now it can't quite be explained why it happens. Went back to |
|
Hello, can you give me your facebook or telegram, i need your help with some exercises |
|
|
|
I am facing the same issues. I think Swift would like us not to touch UI elements in a background thread at all. If necessary, it allows a dispatchQueue to the main thread, just like you said... works flawlessly. Use a perform selector and it throws those purple errors. However, those errors don't seem to stop the working of the app and now seem like somewhat warnings. Just Swift's preferences.... I've learnt to ignore them. |
|
|
|
I got the same exact thing keep coming on, performSelector is defo easier to use then using lots of closures but, must be some solution for this, and from my side is also complainign about "UITableviewController.tableView must be used from main thread only", well .....tableView.performSelector(onMainThread: #selector(UITableView.reloadData), with: nil, waitUntilDone: false) is on the main thread but I have no idea why is keep complaining about this, does anyone have any idea about this ? |
|
DispatchQueue is still a good method to use is not hard. I have used that in project 7 well. Must be a trick around that perfomSelector method.
|
|
The problem ultimately lies in
This says to call
And again in
I solved it like this:
and
I don't know if something changed in Swift since Paul wrote that project or what, but there you go. |
|
Did you use that in fetchJSON method? Also did you use that in combination with performSelector? I see u used a global variable there. Thats actually a very good idea tho, something must has changed, the app is running as normal but Swift is complaning. |
|
I also wrapped tableView into a DispatchQueue block but is still complaining. func parse(json: Data) { let decoder = JSONDecoder() // This is responsable for converting JSON data into Swift code what we can use and display for users.
|
|
Also guys I would suggest to try and filter data, my app is crashing at a certain point |
|
Here's what I did in
And it works without triggering the purple warning about accessing the UI on a background thread. |
|
Okay cool, did you trye to filter the petitions by using search? It worked a couple of times but when I was really stressing it it crashed a couple of times and I can't really tell why, I have the same solution in my code but is just weird something is not right. |
|
I also put the filter code on a background thread like this: performSelector(inBackground: #selector(submit), with: nil) |
|
same problem with purple warnings about main thread https://imgur.com/DGHIoQz Tried everything from offered solutions, in result - app works, but xcode still throwing warnings. I changed code back to previous version with DispatchQueue blocks. |
|
Day 39 definitely needs revision. It simply doesnt work as written. Thanks to this forum. I was able to get it to work. Xcode Version 13.4.1 (13F100) Here are the changes i Had to make: (assume search petitions Challenge is done with search petitions array named as : var searchPetitions = [Petition]() Given below is the corrected code: (not taking credit as its mostly due to other @roosterboy
|
|
Facing same issues. In a background thread, Swift would like us not to touch UI elements. The dispatchQueue can be dispatched to the main thread, as you mentioned... and it works as expected. The purple errors appear when you use a perform selector. While those errors don't seem to stop the app from working, they now seem like warnings. The preferences of Swift... It's become second nature to ignore them |
SAVE 50% All our books and bundles are half price for Black Friday, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.