Blog post about documenting iOS components with the zeroheight API, featuring a colorful graphic design.

Documenting your iOS components using the zeroheight API

Seth Corker
Written by Seth Corker
Jul 16, 2025

Documenting your design system when working with native platforms like iOS and Android can be a bit challenging. On the web, your design system documentation can be dynamic and show off exactly what your components look like. You can embed them in Storybook, or even use the code blocks in zeroheight to show exactly how a component will look (and how it works). How do you show native components beyond just screenshots and videos?

Instead of bringing native components to our documentation, let’s bring documentation closer to our native components by leveraging the zeroheight API, and building a component reference app natively in iOS.

Component documentation in iOS

Storybook on the web is a way to show off your components in isolation, to play around with them, and use as a rapid development environment. We’re going to take this idea and build something native for iOS. We’ll display a list of components to choose from, a preview for a component, and documentation for that component.

To keep things simple, we will be leveraging the following packages:

  • KeychainSwift — a nicer wrapper around the Keychain APIs so we can securely store our API credentials
  • MarkdownUI — a markdown view that supports numerous features we’ll need to show our zeroheight content

Let’s start with the zeroheight API and see how we can get back some documentation.

Using the zeroheight API

The zeroheight API provides access to a page content in Markdown. All we need to provide is a page ID (or UID). This means we can create our documentation on zeroheight and simply copy the UID from of the URL in the zeroheight page we want. We’re following a similar approach to the Storybook add-on.

To get the documentation, we have to do the following:

  1. Get API credentials
  2. Make an API request with those credentials
  3. Decode the request into Swift structs
  4. Display the content

Getting and storing API credentials

We need a Client ID and Access Token to call the zeroheight API, these can be created in your organization settings. These credentials need to be input and stored in the app so we can reuse them whenever we want to request content from the API.

We’ll create a view to ask the user for these details:

AuthCredentialsView.swift
import KeychainSwift
import SwiftUI

struct AuthCredentialsView: View {
    @Environment(\.dismiss) private var dismiss

    @State private var accessToken: String = ""
    @State private var clientId: String = ""

    let keychain = KeychainSwift()

    var body: some View {
        VStack {
            Form {
                TextField("Client ID", text: $clientId)
                SecureField("Access Token", text: $accessToken)
            }

            Button("Login") {
                    keychain.set(accessToken, forKey: "accessToken")
                    keychain.set(clientId, forKey: "clientId")
                }
        }
    }
}

This is a simple form where the user of the app will be able to input their credentials. We leverage KeychainSwift to store them in Keychain so it’s secure and can be used next time we open the app without having to input the credentials again.

A screenshot of the credentials form in a sheet running on iOS

Making an API request

To encapsulate all the logic we need for making a request, I’m creating an APIServicestruct with two static methods:

  • APIService.retrieveCredentials — this will access Keychain and pull out the Client ID and Access Token that was saved by the user.
  • APIService.request — this will retrieve the credentials and make the request. 
import Foundation
import KeychainSwift

struct APIService {
    static func retrieveCredentials() -> (String?, String?) {
        let keychain = KeychainSwift()
        let storedClientId = keychain.get("clientId")
        let storedAccessToken = keychain.get("accessToken")
        
        return (storedClientId, storedAccessToken)
    }
    
    static func request(_ path: String) async throws -> (Data, URLResponse) {
        let credentials = retrieveCredentials()
        
        let url = URL(string: "https://zeroheight.com/open_api/v2/\(path)")!
        var request = URLRequest(url: url)
        request.httpMethod = "GET"
        request.setValue("application/json", forHTTPHeaderField: "Content-Type")
        request.setValue(credentials.0, forHTTPHeaderField: "X-API-CLIENT")
        request.setValue(credentials.1, forHTTPHeaderField: "X-API-KEY")
        
        return try await withCheckedThrowingContinuation { continuation in
            URLSession.shared.dataTask(with: request) { data, response, error in
                if let error = error {
                    continuation.resume(throwing: error)
                    return
                }
                guard let data = data, let response = response else {
                    continuation.resume(throwing: URLError(.badServerResponse))
                    return
                }
                continuation.resume(returning: (data, response))
            }.resume()
        }
    }
}

It’s generic enough that we could also leverage it to bring in more content from zeroheight in the future. For now, we can use this service to make a request to the pages endpoint. 

Making a request for a zeroheight page

We require some models to represent the data we get back from the zeroheight API. When we make a request like: GET https://zeroheight.com/open_api/v2/pages/7735a1?format=markdown

We’ll get a JSON response back that looks like this:

{
  "status": "success",
  "data": {
    "page": {
      "id": 1234,
      "uid": "7735a1",
      "slug": "7735a1-my-page",
      "url": "https://zeroheight.com/123abc/v/latest/p/7735a1",
      "name": "My page",
      "introduction": "This is my page",
      "hidden": false,
      "locked": false,
      "created_at": "2024-11-05T16:09:28.678Z",
      "updated_at": "2024-11-05T16:09:28.678Z",
      "content": "## My page<strong>\n\n</strong>Some content here"
    }
  }
}

For us to be able to use this in our app, we’ll need a representation in Swift. Let’s create some simple models to handle deserializing this data.

struct ZHPage : Codable{
    let id: Int
    let content: String
    let url: String
}

struct ZHPageWrapperResponse : Codable {
    let page: ZHPage
}

struct ZHPageResponse : Codable {
    let status: String
    let data: ZHPageWrapperResponse
}

We’re only interested in a few properties, so I’m skipping all properties of the page except for the ID, the content and the URL for the page.

Now we have a simple representation of a response and the page, let’s see how we might make a request within a view.

func getDocumentation() async {
    do {
        errorMessage = nil
        let (data, _) = try await APIService.request(
            "pages/\(id)/?format=markdown"
        )

        let decoder = JSONDecoder()
        let pageResponse = try decoder.decode(
            ZHPageResponse.self,
            from: data
        )

        page = pageResponse.data.page
    } catch {
        errorMessage =
            "Failed to get documentation. Check your auth credentials and try again."
        print("Error: \(error)")
    }
}

Stepping though the code we:

  1. Make a request to the pages endpoint
  2. Decode the JSON into Swift structs
  3. Set our page or errorMessage state 

This is everything we need to start getting real data into our iOS app.

Navigation

Like Storybook, we want to be able to navigate between different components and to achieve this we need a predictable structure.

Here is something simple to start with:

struct DocumentedComponent : Identifiable {
    let id = UUID()
    let name: String
    let documentationID: String
    let view: AnyView
}

This structure will be used to define our “stories” for each component. We require an id so we can iterate through them in SwiftUI, the name will be used during navigation, the documentationID will be our zeroheight page UID and finally view, this is the SwiftUI view to render. 

Putting it all together, we can start connecting our documentation to our components:

let ComponentDocumentation = [
    DocumentedComponent(
        name: "Primary Button",
        documentationID: "18cce4",
        view: AnyView(
            PrimaryButton(
                text: "Greeting",
                action: {
                    print("action")
                }
            )
        )
    ),
    DocumentedComponent(
        name: "Toggle",
        documentationID: "2166a9",
        view: AnyView(
            VStack {
                Toggle(isOn: .constant(false)) {
                    Text("Enable")
                }.toggleStyle(BrandedToggleStyle())
                Toggle(isOn: .constant(true)) {
                    Text("Enable")
                }.toggleStyle(BrandedToggleStyle())
            }.padding()
        )
    ),
]

Here, we have two components, a button and a toggle. The button shows just the component in one state, and the toggle shows a couple of different states (on and off).

In our SwiftUI view, we can then render a list of our components like so:

NavigationSplitView {
    List(ComponentDocumentation, selection: $activeComponentUUID) {
        documentedComponent in
        NavigationLink(
            documentedComponent.name,
            value: documentedComponent.id
        )
    }
    .navigationTitle("Components")
} content: {
    VStack(alignment: .leading) {
        activeComponent.view
            .padding(50)
            
        Spacer()
    }
    .navigationTitle(activeComponent.name)
    #if os(iOS)
    .navigationBarTitleDisplayMode(.inline)
    .toolbar {
        Button {
            displayDocumentation = true
        } label: {
            Image(systemName: "text.document")
        }
    }
    .toolbarTitleDisplayMode(.inlineLarge)
} detail: {
    Text("Choose a component")
}

You’ll notice a button in the toolbar that controls displayDocumentation, we’ll use this to present an action sheet without our documentation in it.

List view showing Primary Button and Toggle menu items

Displaying markdown

Now we can navigate to a component, the final piece of the puzzle is showing documentation from zeroheight in our app. When a user taps the documentation toolbar button, we want to present a sheet.

.sheet(isPresented: $displayDocumentation) {
    displayDocumentation = false
} content: {
    DocumentationView(id: activeComponent.documentationID)
        .presentationDetents([.medium, .large])
        .presentationDragIndicator(.visible)
        .presentationContentInteraction(.scrolls)
}

The DocumentationView will handle fetching the markdown from the zeroheight API (using our getDocumentation function from earlier)and displaying the markdown simply with Markdown(page.content).

A button in SwiftUI with a bottom sheet showing design system documentation describing implementation and usage example

There we have it, we have documentation for our component, inside a native iOS app. Check out the project if you want to have a look at the code and see how this was done. 

Where do we go from here?

I’ve shown a simple implementation of how to get documentation out of zeroheight and into iOS app, but there is lots more we could do. 

Here are some ideas on what you could do to go even further:

  • Target more of Apple’s platforms, with a few modifications we could bring our design system documentation to tvOS, watchOS, macOS and even visionOS.
  • Follow this approach for Android.
  • Support more complex documentation structures, including tabs.

As long as the platform you want to target supports saving credentials, making a network request and displaying markdown — we can use this approach to view zeroheight documentation anywhere.

Seth Corker
Seth Corker
Try zeroheight
The design systems platform that keeps teams and agents in sync
Start for free
Share this post