Last active
May 11, 2017 16:23
-
-
Save AshishKapoor/3a600dfdd66a4fc0fe0b8d0a70437534 to your computer and use it in GitHub Desktop.
Function returns another function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
// Function returns another function. | |
/* | |
Reference: https://www.youtube.com/channel/UC-d1NWv5IWtIkfH47ux4dWA, The Swift Guy | |
*/ | |
func shouldVerify(_ chooseAction: Bool) -> (String, String) -> String { | |
func verifyThenSendMessage(_ verifyNumber: String, _ sendMessage: String) -> String { | |
// Verify number first then send message logic... | |
return "Verification conducted for number: \(verifyNumber), Message sent: \(sendMessage)" | |
} | |
func sendMessageOnly(_ userNumber: String, _ sendMessage: String) -> String { | |
// No need to veify number just Send it to that particular number | |
return "Verified number: \(userNumber), Message sent: \(sendMessage)" | |
} | |
return chooseAction ? verifyThenSendMessage : sendMessageOnly | |
} | |
let sendVerificationMessage = shouldVerify(true) | |
sendVerificationMessage("9876543210","Please enter the provided OTP"); | |
let sendLoginMessage = shouldVerify(false) | |
sendLoginMessage("9876543210","Welcome back!"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment