I have this code
@objc func didClickActionButton(sender: UITapGestureRecognizer) {
if let contents = contentList {
if contents[currentScreenIndex].customMeta["permission-location"] != nil {
//request Permission
ApiHelper.shared.initLocationHelperWithBeacon()
}
if contents[currentScreenIndex].customMeta["permission-notification"] != nil {
// PushNotificationHelper.requestNotificationAuthorization { }
PushNotificationHelper.requestNotificationAuthorization {
DispatchQueue.main.async {
if self.currentScreenIndex == contents.count - 1 {
self.finishOnboarding()
return
}
self.currentScreenIndex+=1
self.showScreenAtPosition(position: self.currentScreenIndex)
}
}
return
}
if currentScreenIndex == contents.count - 1 {
finishOnboarding()
return
}
currentScreenIndex+=1
showScreenAtPosition(position: currentScreenIndex)
}
}
As you can see I have the same code in the DispatchQueue.main.async
as I have at the bottom at the func. Is there anyway to refactor this so I don't write the same code twice? Is it even worth it to refactor this?