nicklockwood / iVersion

[DEPRECATED]
http://www.charcoaldesign.co.uk/source/cocoa#iversion
Other
1.95k stars 292 forks source link

Threading is bad style/inefficient #91

Open uliwitness opened 7 years ago

uliwitness commented 7 years ago

This code could use some improvement: Currently it starts its own thread to download the data, then starts a synchronous request (which in turn starts its own thread and blocks until that returns). What this should really do is just use one of the asynchronous networking calls (or even better, use NSURLSession's asynchronous calls to fetch the current app version from the app store)

It also does several performSelectorOnMainThread: calls after one another. Each such call has an overhead. It would be much cleaner if it just did one performSelectorOnMainThread: and had that call one method that does the 4 or so calls that need to be on the main thread.

Finally, the way it creates the singleton in +load with performSelectorOnMainThread: waitUntilDone: NO has a race condition. This should really just be using dispatch_once like one does these days to set up a singleton thread-safely.

uliwitness commented 7 years ago

PS - I found this project via your answer to http://stackoverflow.com/questions/6256748/check-if-my-app-has-a-new-version-on-appstore and it was the only answer that wasn't flat-out wrong like most of the others. I'm not actually using this code, or I would have sent you a pull request with the fixes instead of just filing bugs asking you to do it.

nicklockwood commented 7 years ago

@uliwitness I don't disagree. This code predates GCD (iOS 3.x), and has no unit tests, so there's a significant cost/benefit issue with refactoring it. If I ever need to use it myself in a new application, I'll consider a rewrite.