|
| 1 | +# Adding a New Firebase Product Apple SDK |
| 2 | + |
| 3 | +## Introduction |
| 4 | + |
| 5 | +This document provides guidance on many of the factors to consider when designing and developing |
| 6 | +a new Firebase Product Apple SDK. The list is not totally comprehensive and there is ongoing |
| 7 | +evolution, so you should also consult with the iCore team as you are ramping up. |
| 8 | + |
| 9 | +## Swift |
| 10 | + |
| 11 | +While much of Firebase has been implemented in Objective C, any new products or major |
| 12 | +implementations should be implemented in Swift. If Objective C API support is required it should |
| 13 | +be implemented via the Swift `@objc` attribute. Consult with iCore and product management about |
| 14 | +the requirement itself. |
| 15 | + |
| 16 | +Apple and others provide many great guides for Swift programming. Googlers, see also this [2022 |
| 17 | +presentation](go/swift-sdks-2022). |
| 18 | + |
| 19 | +Existing Firebase Swift implementations can be helpful. However, note that they are mostly |
| 20 | +Objective C ports and do not take advantage of Swift features like structs, default arguments, and |
| 21 | +async/await as much as new implementations should. |
| 22 | + |
| 23 | +### Swift Style |
| 24 | + |
| 25 | +Follow this [Style Guide](https://google.github.io/swift/). |
| 26 | + |
| 27 | +Firebase uses [swiftformat](https://github.com/nicklockwood/SwiftFormat) for enforcing code |
| 28 | +formatting consistency. |
| 29 | + |
| 30 | +## Package Managers |
| 31 | + |
| 32 | +Firebase supports four different distributions - Swift Package Manager, CocoaPods, Carthage, and |
| 33 | +binary zip distributions. |
| 34 | + |
| 35 | +Firebase SDKs can be developed via Swift Package Manager or CocoaPods. |
| 36 | + |
| 37 | +The new project should set up a `podspec` for CocoaPods and add a `product` specification to |
| 38 | +the [Package.swift](Package.swift). |
| 39 | + |
| 40 | +## Testing |
| 41 | + |
| 42 | +All Firebase code should be unit tested. Ideally, the unit tests should be driven from both |
| 43 | +CocoaPods and Swift Package Manager. If only one is implemented, it should be SPM. |
| 44 | + |
| 45 | +## Dependencies |
| 46 | + |
| 47 | +Dependencies are a great way to add libraries of well-tested functionality to Firebase. On the flip |
| 48 | +side, they can add bloat and risk to the Firebase user experience. Ideally, only existing Firebase |
| 49 | +dependencies should be used. See [Package.swift](Package.swift). If a new dependency is needed, |
| 50 | +consider making it a weak dependency, implemented with a direct dependency on a protocol instead of |
| 51 | +the full library. New non-protocol-only direct dependencies must be approved by the iCore team. |
| 52 | + |
| 53 | +## Directory Structure |
| 54 | + |
| 55 | +The Firebase library `Foo` should be defined in `FirebaseFoo.podspec`. All of its |
| 56 | +contents should be in the `FirebaseFoo` directory. |
| 57 | + |
| 58 | +* `FirebaseFoo/Sources` - All source. Directory structure is up to the library owner. Any code from a |
| 59 | +non-Google open source project should be nested under a `third_party` directory. |
| 60 | +* `FirebaseFoo/Tests/Unit` - Required (If the library only has unit tests, `Unit` can be omitted.) |
| 61 | +* `FirebaseFoo/Tests/Integration` - Encouraged |
| 62 | +* `FirebaseFoo/Tests/Sample` - Optional |
| 63 | +* `FirebaseFoo/Tests/{Other}` - Optional |
| 64 | + |
| 65 | +## Continous Integration |
| 66 | + |
| 67 | +Set up a GitHub Action workflow for the pod. A good example template is |
| 68 | +[storage.yml](.github/workflows/storage.yml). |
| 69 | + |
| 70 | +All code should comply with Objective-C and Swift style requirements and successfully pass |
| 71 | +the GitHub Action check phase. Run [scripts/style.sh](scripts/style.sh). |
| 72 | + |
| 73 | +## GitHub Infrastructure |
| 74 | + |
| 75 | +For GitHub tag management and public header change detection, add a GitHub api tag and update |
| 76 | +[Dangerfile](Dangerfile). |
| 77 | + |
| 78 | +## Firebase Integration |
| 79 | + |
| 80 | +For top-level Firebase pods that map to documented products: |
| 81 | + |
| 82 | +* Update [Firebase.podspec](Firebase.podspec). |
| 83 | +* Register Swift library by creating a component like |
| 84 | + [Functions example](FirebaseFunctions/Sources/Internal/FunctionsComponent.swift) and |
| 85 | + detecting it in `registerSwiftComponents` in |
| 86 | + [FIRApp.m](FirebaseCore/Sources/FIRApp.m). |
| 87 | +* When ready to release with Firebase, add to the |
| 88 | + [Firebase manifest](ReleaseTooling/Sources/FirebaseManifest/FirebaseManifest.swift). |
| 89 | +* Create an empty JSON file to enable the Carthage build |
| 90 | + [here](ReleaseTooling/Sources/CarthageJSON). |
| 91 | +* Add a [quickstart](https://github.com/firebase/quickstart-ios). |
| 92 | + |
| 93 | +## Review and Release |
| 94 | + |
| 95 | +* Contact icore-eng@ at least a month in advance of desired release date to coordinate the |
| 96 | + initial launch plan. |
0 commit comments