I am using the below code in objective C
to work with semaphore.
-(void)doSome{
semaphore = dispatch_semaphore_create(0);
BaseViewController *baseVC = [[BaseViewController alloc]init];
if(baseVC.isUserObjectExist){
[self callLoginWebService:baseVC.userObject.username passwordString:baseVC.userObject.password];
}else{
dispatch_semaphore_signal(semaphore);
}
while (dispatch_semaphore_wait(semaphore, DISPATCH_TIME_NOW)) { //2
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:100]];
}
}
But
'dispatch_semaphore_t' is unavailable in Swift
How to integrate semaphores in swift 3 ?
you can create by
Learn official document of Apple
OR From other code