Skip to content

OneBusAway/otpkit

Repository files navigation

OTPKit

Swift iOS SPM License Build

otpkit-showcase

Introduction

OpenTripPlanner library for iOS, written in Swift. OTPKit is a reusable library that powers trip planning in the OneBusAway iOS app and can be integrated into any iOS application.

  • Compatible with iOS 18+
  • Works with OpenTripPlanner 1.5.x and higher
  • Licensed under Apache 2.0
  • Provides networking, models, and APIs for building a complete trip planning experience

Quick Start

Installation

Add OTPKit to your iOS project using Swift Package Manager:

dependencies: [
    .package(url: "https://github.com/OneBusAway/OTPKit.git", from: "1.0.0")
]

SwiftUI Usage

import OTPKit

struct ContentView: View {
   var body: some View {
       // 1. Configure OTPKit with server URL and theme
       let config = OTPConfiguration(
           otpServerURL: URL(string: "https://your-otp-server.com")!,
           region: .userLocation(fallback: .automatic),
           themeConfiguration: OTPThemeConfiguration(primaryColor: .blue, secondaryColor: .gray)
       )

       // 2. Create API service for OpenTripPlanner
       let apiService = RestAPIService(baseURL: config.otpServerURL)

       VStack {
           // 3. Add complete trip planner to your app
           OTPView(otpConfig: config, apiService: apiService)
       }
   }
}

UIKit Usage

import OTPKit

let config = OTPConfiguration(
    otpServerURL: URL(string: "https://your-otp-server.com")!,
    region: .userLocation(fallback: .automatic)
)

let apiService = RestAPIService(baseURL: config.otpServerURL)
let tripPlannerView = OTPView(otpConfig: config, apiService: apiService)

// Embed in UIKit using UIHostingController
let hostingController = UIHostingController(rootView: tripPlannerView)
addChild(hostingController)
view.addSubview(hostingController.view)

Development

SwiftLint

OTPKit uses SwiftLint to enforce consistent code style and Swift best practices. Install it locally using Homebrew:

brew install swiftlint

Pre-commit Hooks

The project uses pre-commit to automatically run SwiftLint and tests before pushing to GitHub.

# Install pre-commit (first time setup)
brew install pre-commit

# Install the git hook scripts for pre-push
pre-commit install --hook-type pre-push

# (Optional) Run against all files manually
pre-commit run --all-files --hook-stage pre-push

Once installed, the following checks will run automatically before each push:

  1. SwiftLint - Code style and best practices validation
  2. Xcode Tests - Full test suite must pass

If either linting or tests fail, the push will be blocked until issues are fixed.


About the project

This project was developed as part of Google Summer of Code 2025, created by Manu Rajbhar with guidance from Aaron Brethorst.

You can read the full final report here: GSoC 2025 Final Report – OTPKit

License

Licensed under Apache 2.0. See LICENSE for more details.

Contributors

OTPKit was originally created as a Google Summer of Code project.

About

OpenTripPlanner library for iOS, written in Swift

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 5

Languages