Risks of using performSelectorInBackground?

I tested with ObjectiveResource (iOS-> Rails bridge). Everything seems to work, but the library is synchronous (or maybe not, but the mailing list that supports it is a mess ).

I am wondering what pitfalls should just run all the calls inperformSelectorInBackground ... in small tests, it looks like they are working fine, but this is the case with many things that are wrong.

The only caveat I noticed is that you should create the Autorelease pool in the method executed by the performSelectorInBackground function (and then you should only call drain, not release?).

+3
source share
2 answers

performSelectorInBackground:uses threads behind the scenes, and the great thing with threads is that any piece of code affected by more than one is a minefield for race conditions and other subtle mistakes. This obviously means that drawing on the screen goes beyond the mainstream. But there are many other libraries that are also not thread safe, and any code using them is also corrupted.

, - , , , . ObjectiveResource , . , , URL-, IIRC. ObjectiveResource- . , , , performSelectorInBackground: , .

, 1.1 Github async ConnectionManager. , ( , emptor).

+8

- ? ?

, . . ():

- (void)viewWillAppear:(BOOL)animated {
    [self performSelectorInBackground:@selector(refreshTableView)];
    [super viewWillAppear:animated];
}

- (void)refreshTableView {
    // Where _listOfObjects is used to populate your UITableView
    @synchronized(self) {
        self._listOfObjects = [MyDataType findAllRemote];
    }
    [self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:YES];
}

( ), , , self, (, thread) _listOfObjects . ( "" .)

100% ( ), , _listOfObjects atomic, . , @property, , . (, / NSMutableArray.)

+8

Source: https://habr.com/ru/post/1784607/


All Articles