Skip to content

pluto/pluto-swift-sdk

Repository files navigation

PlutoSwiftSDK

PlutoSwiftSDK is a Swift library that provides tools for proof generation and includes a reusable BrowserView component.

Features

  • Proof generation for your provided configuration.
  • Reusable BrowserView component based on WKWebView.

Requirements

  • macOS: 11.0 or later
  • Xcode: 14.0 or later
  • iOS: 12.0 or later
  • Swift: 5.0+

Getting Started

1. Clone the Repository

git clone https://github.com/yourusername/PlutoSwiftSDK.git
cd PlutoSwiftSDK

2. Build the Framework

Open the Xcode project:

open PlutoSwiftSDK.xcodeproj

Select the PlutoSwiftSDK scheme and build it with Cmd + B.

3. Run the Test App

Select the PlutoSDKTestApp scheme and run it:

Cmd + R

4. Run Unit Tests

Run the tests in Xcode with Cmd + U. Or from the terminal:

xcodebuild test -scheme PlutoSwiftSDK -destination 'platform=iOS Simulator,name=iPhone 14'

Folder Structure

PlutoSwiftSDK/
├── Sources/                 # Source code
│   ├── Enums.swift          # Enums
│   ├── ManifestModels.swift # Models for manifest
│   ├── ManifestParser.swift # JSON parsing
│   ├── BrowserView.swift    # BrowserView component
│   └── PlutoSDK.swift       # Public API
├── Tests/                   # Unit tests
├── PlutoSDKTestApp/         # Sample app
├── PlutoSwiftSDK.xcodeproj  # Xcode project
└── README.md                # Project documentation

Using PlutoSwiftSDK in Your Project

Swift Package Manager

  1. Open Xcode and go to File > Swift Packages > Add Package Dependency.
  2. Enter the repository URL: https://github.com/yourusername/PlutoSwiftSDK.git

CocoaPods

  1. Add this to your Podfile:
pod 'PlutoSwiftSDK', :git => 'https://github.com/yourusername/PlutoSwiftSDK.git'
  1. Run
pod install

Example Usage

Proof Generation

import PlutoSwiftSDK

let manifestConfig = """
{
    "manifestVersion": "1.0",
    "id": "1234",
    "title": "Sample",
    "description": "This is a test.",
    "mode": "TLSN",
    "request": {
        "method": "POST",
        "url": "https://example.com/api",
        "headers": { "Content-Type": "application/json" },
        "body": "{\\"key\\":\\"value\\"}"
    },
    "response": {
        "status": "200",
        "headers": {},
        "body": {
            "json": [["key", "value"]],
            "contains": "success"
        }
    }
}
"""

if let manifest = PlutoSDK.parseManifest(config: manifestConfig) {
    print("Manifest ID: \(manifest.id)")
}

BrowserView Component

import PlutoSwiftSDK
import UIKit

let browserView = BrowserView(frame: someView.bounds)
browserView.load(url: URL(string: "https://example.com")!)
someView.addSubview(browserView)

Contributing

  1. Fork the repository.
  2. Create a new branch.
  3. Commit and push your changes.
  4. Open a pull request.

License

This project is licensed under the MIT License.

Contact

GitHub: pluto

Twitter: @plutolabs_

Release

First, update the version in the PlutoSwiftSDK.podspec file.

make release

This will archive the framework, zip it up, and give you a sha256 of it. Next, upload the zipped file to the GCP Bucket. Once that is uploaded, grab the public URL and update the PlutoSwiftSDK.podspec file with the new URL and sha256.

Finally, publish then new version to CocoaPods:

pod trunk push PlutoSwiftSDK.podspec