I've started refactoring my code recently and I'm trying to increase performance by using more threads. Especially for downloads and connections. I've had a function called...
- (UIImage *)imageFromURLString:(NSString *)urlString;
...which just establishes a connection, creates an UIImage from the received data und returns it.
Now I've started working with threads and I realized that I can't get a return value (which makes sense as the thread runs separatly from the method it is been called from). What would be the "best" / most elegant way, to solve problems of this kind in general?
- Should I just create an atomic class variable and fill it from within the former function?
- Maybe passing a pointer to an UIImage object to the method and fill it from within?
I'm aware that using a class variable would be the easiest solution, but it doesn't seem very "clean" nor optimal to me. Thanks in advance!