Install for SwiftUI
Requires iOS 17 or newer. The component is a Swift package with the module name Nitpick.
You need a Nitpick account with a running subscription to get an app and a public key. nitpick login opens the browser where you create the account and start the subscription; see Billing and limits. The component itself needs nothing but the public key.
Quickest: run nitpick init
In the folder of your repository:
npx -y @nitpickhq/cli@latest init
init finds the app, links it to an app on your Nitpick account (or creates one), writes nitpick.json, adds the Swift package, writes the Nitpick.configure line in the init() of your @main App where it is sure of the code, and prints what is left. It adds the package to a Package.swift or to a current-format .xcodeproj itself, so you do not edit project.pbxproj; Xcode can stay open. It needs a login first (nitpick login) and iOS 17 or newer. For an XcodeGen or Tuist project, an older Xcode project format or code it does not recognise, it changes nothing there and gives the step to do. Run nitpick doctor afterwards to check the setup. All options: CLI reference. When something stops, see Troubleshooting.
By hand
If you prefer to do it yourself, or init gave you a manual step, these are the steps. Sections 3 to 5 apply after init too.
1. Add the package
An app with an .xcodeproj. Add the package in Xcode; it takes half a minute and cannot break the project file:
- File, Add Package Dependencies.
- Paste
https://github.com/nitpickhq/nitpick-swiftin the search field. - Dependency Rule: Up to Next Major Version, from
0.3.0. Add Package. - Add the product
Nitpickto your app target. Add Package.
Agents: run nitpick init, which adds the package itself; do not edit project.pbxproj yourself. Only for an older Xcode project format, or another case where init gives this manual step, ask the user to do these four steps and wait until they say it is done, then build.
A generated project (XcodeGen or Tuist). The .xcodeproj is output, so a change in it is lost at the next generate. With XcodeGen add the package to project.yml (packages: with the URL above and from: 0.3.0, and - package: Nitpick with product: Nitpick under the app target's dependencies), then run xcodegen generate. With Tuist add the package to Tuist/Package.swift and .external(name: "Nitpick") to the app target, then run tuist install and tuist generate.
A Swift package. In Package.swift:
dependencies: [
.package(url: "https://github.com/nitpickhq/nitpick-swift", from: "0.3.0"),
],
targets: [
.target(name: "YourApp", dependencies: [.product(name: "Nitpick", package: "nitpick-swift")]),
]
The package ships a privacy manifest (PrivacyInfo.xcprivacy) with the reasons Apple requires, so you do not write one for it.
2. Configure
import SwiftUI
import Nitpick
@main
struct HabitsApp: App {
init() {
Nitpick.configure(appKey: "npk_YOUR_PUBLIC_KEY")
}
var body: some Scene {
WindowGroup {
RootView()
}
}
}
The public key is safe to ship in the app. It can only create reports for this one app.
Nitpick.configure(appKey:) in the init of the App puts the edge tab and the panel in place. .nitpick() on a view is optional: it only makes sure the component is attached when that view appears, so you can leave it out.
Use your own button instead of the edge tab:
Nitpick.configure(appKey: "npk_...", options: NitpickOptions(showsTab: false))
Button("Send feedback") { Nitpick.present() }
Show the tab only on some screens: pass the names you gave them with .nitpickScreen.
Nitpick.configure(appKey: "npk_...", options: NitpickOptions(tabScreens: ["Checkout", "Settings*"]))
A name must be equal to the screen name (capitals count). A name that ends on * matches every screen whose name starts with what comes before the *: "Settings*" matches Settings and Settings/Profile. The tab shows on the current screen only when its name is in the list, and never on a screen without a name. An empty list shows the tab nowhere (one line in the developer log), and showsTab: false always wins. The panel stays open when the screen changes, and Nitpick.present() works on every screen. Without tabScreens the tab shows on every screen.
Nitpick.present() does nothing while no settings have been fetched yet, while the app is switched off, or when both kinds are off. Nitpick.isAvailable tells you, so the button can hide itself.
The component asks the platform for your settings when the app starts, and keeps the last good answer in UserDefaults. Use NitpickOptions(dryRun: true) to try it without a network: the tab shows at once and nothing is sent.
3. Name screens and elements
Names are what let your agent jump from a report to the right file. Use a name that points at the code, such as Home/StartButton.
struct HomeView: View {
var body: some View {
VStack {
Button("Start workout", action: start)
.nitpickElement("Home/StartButton")
}
.nitpickScreen("Home")
}
}
See Screens, elements and masking for what to mark and how matching works. In a List, mark the content of a row, not a Button that is the row itself.
4. Mask sensitive parts
Text(account.iban).nitpickMask()
5. Test it
Build and run (you cannot tap in the simulator as an agent: ask the builder to do the tapping), wait a moment for the settings to arrive, and if you chose screens with tabScreens, go to one of them first: the tab shows only there. Then open the tab, tap "Point at something", tap an element and send. The report shows up in your dashboard, and in nitpick feedback list.
Next: Theme, where you choose a color and a font, and Settings.