Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Swift/Xcode: Need to create the following in a playground on Xcode. Create a fun

ID: 3743687 • Letter: S

Question

Swift/Xcode: Need to create the following in a playground on Xcode.

Create a function, called check, that takes in an Int and returns an optional String.

The input parameter should be called value.

If the passed in argument is negative or zero, return nil.

Else return a string version of the argument.

Example:

let numberString1: String? = check(value: 10) // numberString should be "10"

let numberString2: String? = check(value: 0) // numberString should be nil

let numberString3: String? = check(value: -2) // numberString should be nil

Explanation / Answer

Below is the Swift code I hope that i have provided sufficient comments for your better understanding Note that I have done proper indentation but this code is automatically left alligned on this interface

func xyz(value: Int) -> String {
// Check whether number is positive
if x > 0
{
var myString = String(value)
}
else
{
var myString = "nil"
}
return myString
}

let numberString = xyz(10)
printnumberString

Hope i have answered your question satisfactorily.Leave doubts in comment section if any.