Reputation: 3860
So, I got a monster code at my viewDidLoad on my first view. Well I am allocating 7 of my own objects, so it looks like this
OwnObject *o1 = [[OwnObject alloc] initWithValuesString:@"blabla" image:[UIImage named:@"blabla"]];
OwnObject *o2 = [[OwnObject alloc] initWithValuesString:@"blabla" image:[UIImage named:@"blabla"]];
And so on...
I was watching a session video once again at apple developer and they said that I should use GCD to speed things up, so could I speed my app by putting that to dispatch queue?
Note that my view loading isn't very slow, but I am just wondering should I usually put things like that in dispatch queue.
Thanks, sorry if this is stupid.
Upvotes: 2
Views: 369
Reputation: 70946
If those allocations don't do things which require the main thread (e.g. touching the UI) then they could be done via GCD in a queue. You'd want to use dispatch_async
, because with a synchronous call you'd still have to wait until the allocations completed and would gain nothing. Also, you'd need to be sure that your view controller was designed to handle finishing viewDidLoad
without having those objects allocated yet, since the async dispatch call would be, well, asynchronous. You would probably either need to post a notification that allocation had completed or use dispatch_group_notify
so that the view controller would know when the allocations were complete and could start using the objects.
Unless these allocations take a long time, this is likely to be more trouble than it's worth.
Upvotes: 4