一次性代码

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"----touchesBegan");
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{

       // NSLog(@"----once"); 只会打印一次
        NSLog(@"----once");
    });
}
原文地址:https://www.cnblogs.com/nxz-diy/p/5365684.html