Swiftify-Corp / Swiftify

42 stars 24 forks source link

Multi line strings are not correctly converted #236

Closed AlexanderJ closed 1 year ago

AlexanderJ commented 1 year ago

In this example: https://swiftify.me/s85ur1

The objective-c multiline string is not correctly handled (using \ to continue on the next line). In this case the \ symbol at the end of the line needs to be removed from the result (otherwise the result is correct.

alex-swiftify commented 1 year ago

@AlexanderJ Your input Objective-C code builds the following string, which does not contain line breaks:

{ "created":"2021-07-01T09:35:17Z",                                            "caseId":"3.3.53dbf.c7001bfd",                                            "caseTitle":"Ship Order test - 000080773",                                            "id":"0.0.517fb.1f0008d5",                                            "title":"Test User"                                            },                                            "content":"test 3 @Miguel Penades" }

I've just verified this with a test app: https://take.ms/5dL7h

The resulting Swift code also builds the string without line breaks: https://take.ms/gZquu

Reading from https://docs.swift.org/swift-book/LanguageGuide/StringsAndCharacters.htm

When your source code includes a line break inside of a multiline string literal, that line break also appears in the string’s value. If you want to use line breaks to make your source code easier to read, but you don’t want the line breaks to be part of the string’s value, write a backslash () at the end of those lines

Thus, the output with \ characters most closely resembles the input Objective-C code, while without \ characters the Swift string will contain a newline character after each line.

I agree that for your sample JSON newlines don't matter and the \ character could be removed for better readability, however, I don't find anything to be fixed in our converter. If you see it otherwise, let us know.

AlexanderJ commented 1 year ago

Sorry, you're right. I double checked. The \ in swift was actually avoiding the newline in the result and thus produced exactly the same string as the objective-c before.