If you're interested in contributing to the Swift Protobuf project, welcome! Please make sure that your APIs are named and code is formatted according to these guidelines so that we can ensure a consistent look-and-feel across the entire codebase.
The following guidelines are non-exhaustive.
When in doubt about how to format a particularly tricky construct (such as a method with a large number of generic types and/or arguments), we suggest two pieces of advice:
Foo.swift
would contain a type named Foo).
ProtobufBinaryTypes.swift file contains multiple small related types.Type+Protocol.swift so the content
and purpose of the file is easily glanceable based on the name and so that it
is easy to find the source file where a particular concept is implemented.
Types+Protocol.swift.- Parameter foo:
and - Returns: tags when the meanings of parameters and return values are
not obvious from the other documentation. Use - Throws: tags to describe
which errors are thrown and under which circumstances.The official Swift API Design Guidelines are a good source of wisdom when designing a new API.
Some points of emphasis:
serializedSize().Void should be named with
imperative verbs or verb phrases; for example, encode(value:).color,
encodedSize, etc.is, such as isEmpty, or indicative verb phrases
such as intersects.Collection.Encoding) or -able/-ible adjectives (Encodable).At the time of this writing, some of the code in this project does not conform to these guidelines (as it was written before the guidelines were adopted). As changes are made, old code will be opportunistically brought in line with these guidelines.
Eventually, it is our hope that the swift-format tool that is in Swift's
main branch will be made generally available with a future release of Xcode
or in some other form that is easy for end-users to adopt.