CUSTOM_VIEW CLASS:
I have made custom_view class which calculates value on itself and shows to user after every 1 sec. Calculation of values in custom_view based on properties/variable stored in custom_view instance.
VIEWCONTROLLER CLASS:
I display some 7 to 9 view's by creating instance of custom_class in VIEWCONTROLLER class.
As my custom_class shows new calculated value after every 1 sec, i have used dispatch_async to execute the code of calculation. So that it won't affect UI Thread.
custom_view.m
static dispatch_queue_t queue;
queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND,0);
dispatch_async(queue, ^(void)
{
[self calculateViewValue];
});
-(void) calculateViewValue
{
int wait = [self generateRandomNumberWithlowerBound:10 upperBound:20];
for (int i = 0; i<= wait; i++)
{
// value calculation
[[NSOperationQueue mainQueue] addOperationWithBlock:^
{custom_view_instance.text = value;}];
sleep(1);
}
}
However, After executing it iPhone heats up after some time!! Am i doing something wrong / missing / best way to do it ???