开发者

NSTimer in a for loop

开发者 https://www.devze.com 2023-04-12 01:42 出处:网络
I want to call the getData method after waiting 2 seconds each time this loop...l开发者_开发问答oops.I\'ve written out the NSTimer a number of times inside and outside the loop but can\'t get the corr

I want to call the getData method after waiting 2 seconds each time this loop...l开发者_开发问答oops. I've written out the NSTimer a number of times inside and outside the loop but can't get the correct usage for it to do what I want.

for (TwitterPerson *person in [tempDict allValues]) {

        [self getDataFromTwitterUserAPIandArchiveFor:person.handle];

    }


Could you set it up differently and call the [getData... method every time the timer fires? You could keep your dictionary keys in an array and pop the next key each time the timer fired.

I think the NSTimer is designed to not block the main thread whereas the for-loop definitely blocks the thread.

As in this related question Using NSTimer in a Loop, you might consider NSRunLoop.

0

精彩评论

暂无评论...
验证码 换一张
取 消