Date in a 3 different styles

I solved this challenge and it works perfectly in playground, put it does not work in the challenges platform.
The challenge is about taking the date as string and generate 3 styles as in the uploaded pic.
My solution:

func date_format2(date: String ) -> String {
    let inputFormatter = DateFormatter()
    inputFormatter.dateFormat = "YYYY/m/d"
    let showDate = inputFormatter.date(from: date)
    let outPutFormatter = DateFormatter()
    outPutFormatter.dateFormat = "YYYY/m/d" + " | " + "YYYY-m-d" + " | " + "m/d/YYYY"

    let resultString = outPutFormatter.string(from: showDate!)
     return resultString
 }
print(date_format2(date: "2020/1/1"))
// **output**:2020/1/1 | 2020-1-1 | 1/1/2020

What challenge platform are you referring to?

it is a local platform. Do you think my code is incorrect. it works perfectly in playground.

Is the platform using Swift code?

yes it uses Swift

Is it an Xcode project that you are using the code in?

No it is not a completed project. I am using playground. Just a simple function.

So if the function works in playground, what is the issue with the “Challenge platform”?

I don’t know, it just says: INCORRECT

I posted this question to know if I did wrong formats or something.

Given that it works in playground it should work just fine in a project.

Share your code where you get the error.

Paste your code in as text, rather than providing a screenshot.

Place 3 back-ticks ``` on the line above your code and 3 back-ticks ``` on the line below your code so that it is formatted nicely. The back-tick character is located on the same keyboard key as the tilde character ~.

This also makes it easier for anyone assisting as they can copy the code and carry out some testing rather than having to type the code in from an image.

1 Like

The problem is that the platform did not import Foundation library by default. When I added it, the platform accepted my code.