I've looked around but was suprised that I couldn't really find anything that explained this. If I have:
func checkEmail () { var test = true return test } ...elsewhere in the code.... var emailStatus = checkEmail ()
How can I make this function return the boolean value of true?
The method is called isOriginal() , and it takes one parameter that's a string. But before the opening brace there's something important: -> Bool . This tells Swift that the method will return a boolean value, which is the name for a value that can be either true or false.
A Boolean function is like a built-in function except that it returns a value of true or false instead of number, string, or date. The result of a Boolean function cannot be printed; it can only be used as a condition. A Boolean function is composed of a function name followed by an operand in parentheses.
If you want to return your own value from a function, you need to do two things: Write an arrow then a data type before your function's opening brace, which tells Swift what kind of data will get sent back. Use the return keyword to send back your data.
func checkEmail() -> Bool { var test = true return test }
Elsewhere in the code....
var emailStatus = checkEmail()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With