我想你已经发现了调度组!
有上千篇文章,没有必要在这里毫无意义地粘贴一些东西,
等待多个网络请求全部执行 - 包括它们的完成块 https://stackoverflow.com/questions/10643797
cheers!
在更简单的层面上,您正在寻找的可能只是简单的“突破代码”这是编写简单、整洁的代码的关键部分。请注意,这并不总是解决方案,但通常 - 而且,我也不是 100% 清楚你所问的问题。但在脱离代码中,你会像这样......
{
do something;
if ( failure, and you don't want to do any more ) return;
do some other important thing;
if ( failure of that thing, and you don't want to do any more ) return;
do yet another routine here;
if ( some other failed conditions, and you don't want to do any more ) return;
}
这是一个典型的例子。通常你会看到类似这样的代码......
-(void)loadNameInToTheCell
{
if ( self.showname != nil && [self.showname notLike:@"blah"] && kount<3 )
{
// many many lines of code here
// many many lines of code here
// many many lines of code here
}
}
你跟我?但这样写会好得多:
-(void)loadNameInToTheCell
{
if ( self.showname == nil ) return;
if ( [self.showname notLike:@"blah"] return;
if ( kount<3 ) return;
// many many lines of code here
// many many lines of code here
// many many lines of code here
}
说得通?
请注意,重要的是,在任何实际项目中,它都是关于文档而不是代码,因此您可以适当地讨论和评论......
-(void)loadNameInToTheCell
{
if ( self.showname == nil ) return;
// don't forget Steve's routine could return nil
if ( [self.showname notLike:@"blah"] return;
// should we worry about caps here?
if ( kount<3 ) return;
// client wants to change this to 4 in future - Steve
// screw that ... Biff, 8/2014
// many many lines of code here
// many many lines of code here
// many many lines of code here
}
有道理吧?我希望这对您所问的问题有所帮助。你必须“反过来想”你知道吗?
一个可能的经验法则是,如果你有一个条件,然后是一个“很长的代码块”——这有点错误。将其转向另一个方向并具有分离条件。只有这样,才有“实际的相关代码”。从某种意义上说..永远不要将一长串重要的代码放在if块中;如果是这样的话,你的想法有点错误。