Iām setting up Apollo in an app for the first time, and I have noticed that Apollo and Xcode 10.2 disagree about whether a file should end in a trailing newline, causing the file to be modified every time it is opened or the project is built.
Intended outcome:
Apollo should generate an API.swift with a newline \n character at the end of the file.
Actual outcome:
Apollo generates an API.swift that does not have a newline \n character at the end of the file. Every time Xcode 10.2 opens the file, it adds a newline to the end of the file. Every time the project is built, Apollo removes the trailing newline.
How to reproduce the issue:
API.swift to your Xcode projectAPI.swift in Xcode, and see that Xcode adds a newline to API.swiftAPI.swift without a newlineWhat Text Editing Preferences are you using? I could not reproduce this with Xcode Version 10.2.1 (10E1001).

Anyone else seeing this issue?
It looks like, while Xcode automatically modifies the file when itās opened (see screenshot indicating modified file), I still have to save the file for the additional whitespace to be reflected on the filesystem.

I have āAutomatically trim trailing whitespaceā and āIncluding whitespace-only linesā enabled, but āConvert existing files on saveā disabled. However, I still experience the issue if I copy your settings exactly. I also experience the issue when I use Xcode 10.1.

To better illustrate my issue, hereās the end of the output of cat API.swift as generated by Apollo:

And hereās the end of the output of cat API.swift after Xcode appends a trailing newline:

Note how the last brace of the Apollo-generated file appears on the same line as my command prompt, while the last brace of the Xcode-modified file appears on its own line, as expected.
According to the POSIX standard, each line in a file, including the last line, should end in a newline \n character. GNU and Unix tools like cat expect this behavior, so they donāt behave nicely when a file does not end in a trailing newline.
Thank you for the detailed follow-up. Sounds like I should be able to reproduce it. However, thereās some subtlety to it, a freshly generated file looks fine here.

When I use Vim with :set list!, my freshly generated file shows a newline $ too, but if I save the file from Vim, Git shows that thereās now a new line. It looks like Vim also inserts the newline if it isnāt already present.
I think thatās default behavior, but just in case, hereās my ~/.vimrc:
syntax enable
set incsearch
set hlsearch
autocmd FileType gitcommit setlocal spell textwidth=72
Confirmed š

Although, from a quick glance, I reckon this is not Swift specific, I will try expose this issue with a test for apollographql/apollo-tooling/packages/apollo-codegen-swift.
I guess writing TypeScript is a thing I do now. š¤·āāļø
This has been addressed by switching to the updated code generation in 0.13.0!
Most helpful comment
This has been addressed by switching to the updated code generation in 0.13.0!