I use xcodegen to genreate a Xcode project that has the ability to run scripts. This lets me see swiftlint warnings in Xcode while developing packages.
This tool creates a Xcode project from a project.yml definition. In that definition, you can add a script that runs swiftlint as a post compile task. Example.
Advantages of this method:
- swiftlint warnings in Xcode.
- Xcode settings beyond what SPM offers.
Disadvantages:
- You rely on a third-party tool that could break or go away. However, you can drop this dependency at any time and go back to edit the Package.swift in Xcode.
- You need to learn to write project.yml files.
- If you use SPM bundles you need to generate the bundle accessor yourself.
A word about generating a bundle accessor. This is needed when working from a Xcode project because only SPM generates the file resource_bundle_accessor.swift
to the project. If you already compiled after opening the Package.swift
with Xcode, the file should be here:
find ~/Library/Developer/Xcode/DerivedData* -iname resource_bundle_accessor.swift
You can add it to the project, but if you are creating a framework, the bundle accessor can be as simple as:
import class Foundation.Bundle
// This file is only used when using a xcodegen-generated project.
// Otherwise this file should not be in the path.
private class BundleFinder {}
extension Foundation.Bundle {
static var module = Bundle(for: BundleFinder.self)
}