Saturday 15 August 2015

ios - Load UIImage in background Thread -



ios - Load UIImage in background Thread -

is possible load uiimage in background thread without causing threading problems? if not best way of doing it? i'm using ios 8. way right now:

dispatch_queue_t backgroundqueue = dispatch_get_global_queue(dispatch_queue_priority_background, 0); dispatch_async(backgroundqueue, ^{ uiimage *image = [uiimage imagenamed: filename]; // update ui on main thread dispatch_async(dispatch_get_main_queue(), ^{ [self setimage: image]; }); });

what you're doing structurally sound, don't know whether imagenamed: thread-safe — , have no reason believe is. should assume things not thread-safe unless told otherwise documentation. in case, documentation says not:

you can not assume method thread safe.

in view, should inquire whether need @ all. imagenamed: includes caching mechanism should relieve of whatever worried about. in case, premature optimization waste of time , brainpower. there issue here? utilize instruments find out; don't utilize intuition or instinct.

if problem images big , in bad selection of format — example, using big jpegs — improve concentrate on correcting that.

edit ios 9 documentation says: "in ios 9 , later, method thread safe." suggests both reply right , problem solved.

ios objective-c multithreading uiimage ios8

No comments:

Post a Comment