Since upgrading to Xcode 9.3/Swift 4.1, I noticed that code coverage percentage dropped in several of my projects.
The bug seems to occur when I use conditional code within an initializer:
Neither the if/else branches nor the switch cases are counted towards line coverage when compiling with Xcode 9.3 and "Gather coverage" turned on.
I wrote test cases (see attached project "Codepath.zip") that exercise the code paths in question and verified their execution with the debugger.
Older Xcode versions or the swift-4.0.3-RELEASE-osx toolchain from swift.org report correct percentages when I enable code coverage in the Test phase of the scheme.
I also tested the behaviour with a command line tool (see attached project "codepath-cli.zip") and
When using Xcode 9.3's default toolchain, conditional code within the initializer is not reached. When using the 4.0.3 final toolchain, all conditional code is counted correctly (at least once).
The test CLI tool project contains xcrun-based scripts to generate & show coverage for the Xcode default toolchain (showCoverageSwift41.sh) and the final 4.0.3 toolchain (showCoverageSwift403).