Getting Started with Reachu Swift SDK
Get up and running with the Reachu Swift SDK in your iOS, macOS, tvOS, or watchOS application in just a few minutes.
Prerequisites
- Xcode 15.0 or later
- iOS 15.0+, macOS 12.0+, tvOS 15.0+, or watchOS 8.0+
- Swift 5.9 or later
- A Reachu account with API credentials
Step 1: Installation
Swift Package Manager (Recommended)
Add the Reachu Swift SDK to your project using Xcode:
- Open your Xcode project
- Go to File → Add Package Dependencies...
- Enter the repository URL:
https://github.com/ReachuDevteam/ReachuSwiftSDK.git
- Select the version (use the latest stable release)
- Choose your modules based on your needs
Manual Package.swift
If you're using Swift Package Manager directly, add this to your Package.swift
:
// swift-tools-version: 5.9
import PackageDescription
let package = Package(
name: "YourApp",
platforms: [
.iOS(.v15),
.macOS(.v12),
.tvOS(.v15),
.watchOS(.v8)
],
dependencies: [
.package(url: "https://github.com/ReachuDevteam/ReachuSwiftSDK.git", from: "1.0.0")
],
targets: [
.target(
name: "YourApp",
dependencies: [
// Choose your modules (see module selection below)
.product(name: "ReachuUI", package: "ReachuSwiftSDK"),
]
),
]
)
Step 2: Choose Your Modules
The Reachu Swift SDK is modular. Import only what you need:
Core Only (Minimal Size)
.product(name: "ReachuCore", package: "ReachuSwiftSDK")
Use for: Headless ecommerce, custom UI, server-side Swift
Core + UI Components (Recommended)
.product(name: "ReachuUI", package: "ReachuSwiftSDK")
Use for: Most iOS/macOS apps with ecommerce features
Core + Live Shopping
.product(name: "ReachuLiveShow", package: "ReachuSwiftSDK")
Use for: Apps with livestream shopping without UI components
Complete SDK (All Features)
.product(name: "ReachuComplete", package: "ReachuSwiftSDK")
Use for: Full-featured ecommerce apps with livestreaming
Step 3: SDK Configuration
Option A: App Delegate Setup
import UIKit
import ReachuCore
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
// Configure Reachu SDK
ReachuSDK.configure(
baseURL: "https://graph-ql-dev.reachu.io",
apiKey: "your-api-key-here",
environment: .development // or .production
)
return true
}
}
Option B: SwiftUI App Setup
import SwiftUI
import ReachuCore
@main
struct MyApp: App {
init() {
ReachuSDK.configure(
baseURL: "https://graph-ql-dev.reachu.io",
apiKey: "your-api-key-here",
environment: .development
)
}
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
Environment Configuration
Use different configurations for development and production:
import ReachuCore
extension ReachuSDK {
static func configureForEnvironment() {
#if DEBUG
ReachuSDK.configure(
baseURL: "https://graph-ql-dev.reachu.io",
apiKey: "dev-api-key",
environment: .development
)
#else
ReachuSDK.configure(
baseURL: "https://graph-ql.reachu.io",
apiKey: "prod-api-key",
environment: .production
)
#endif
}
}
Step 4: Your First Implementation
Basic Product Display
import SwiftUI
import ReachuUI
import ReachuCore
struct ProductListView: View {
@StateObject private var viewModel = ProductViewModel()
var body: some View {
NavigationView {
ScrollView {
LazyVGrid(columns: [
GridItem(.flexible()),
GridItem(.flexible())
], spacing: 16) {
ForEach(viewModel.products) { product in
RProductCard(
product: product,
variant: .grid,
onTap: {
// Navigate to product detail
},
onAddToCart: {
viewModel.addToCart(product)
}
)
}
}
.padding()
}
.navigationTitle("Products")
.task {
await viewModel.loadProducts()
}
}
}
}
ViewModel Implementation
import Foundation
import ReachuCore
@MainActor
class ProductViewModel: ObservableObject {
@Published var products: [Product] = []
@Published var cart: Cart?
@Published var isLoading = false
private let sdk = ReachuSDK.shared
func loadProducts() async {
isLoading = true
defer { isLoading = false }
do {
self.products = try await sdk.channel.product.getAll(
currency: "USD",
limit: 20
)
} catch {
print("Failed to load products: \(error)")
}
}
func addToCart(_ product: Product) async {
do {
if cart == nil {
cart = try await sdk.cart.create(
customerSessionId: UUID().uuidString,
currency: "USD"
)
}
cart = try await sdk.cart.addItem(
cartId: cart!.id,
productId: product.id,
quantity: 1
)
} catch {
print("Failed to add to cart: \(error)")
}
}
}
Step 5: Testing Your Setup
Using Mock Data
For development and testing, use the built-in mock data:
import SwiftUI
import ReachuUI
#if DEBUG
import ReachuTesting
struct TestView: View {
private let mockProducts = ReachuMockDataProvider.shared.sampleProducts
var body: some View {
ScrollView {
VStack(spacing: 16) {
ForEach(mockProducts) { product in
RProductCard(
product: product,
variant: .hero,
showDescription: true
)
}
}
.padding()
}
}
}
#Preview {
TestView()
}
#endif
SwiftUI Previews
The SDK includes preview support for easy development:
#if DEBUG
import SwiftUI
import ReachuUI
import ReachuTesting
struct ProductCard_Previews: PreviewProvider {
static var previews: some View {
Group {
RProductCard(
product: ReachuMockDataProvider.shared.sampleProducts[0],
variant: .grid
)
.previewDisplayName("Grid Variant")
RProductCard(
product: ReachuMockDataProvider.shared.sampleProducts[1],
variant: .hero,
showDescription: true
)
.previewDisplayName("Hero Variant")
}
.previewLayout(.sizeThatFits)
.padding()
}
}
#endif
Common Issues & Solutions
Issue: Module not found
error: No such module 'ReachuUI'
Solution: Make sure you've added the correct module to your target dependencies and that the package has been resolved successfully.
Issue: Minimum deployment target
error: compiling for iOS 14.0, but module requires iOS 15.0
Solution: Update your deployment target to iOS 15.0 or later in your project settings.
Issue: GraphQL connection errors
error: Network request failed
Solution: Check your API key and base URL. Make sure you're using the correct environment configuration.
Next Steps
Now that you have the SDK set up, explore these areas:
- UI Components - Learn about available SwiftUI components
- API Reference - Dive deep into SDK methods
- Examples - See complete implementation examples
🌓 Dark/Light Mode Support
Reachu SDK provides complete dark/light mode support out of the box! All UI components automatically adapt to iOS system settings.
Quick Setup
Add theme configuration to your reachu-config.json
:
{
"theme": {
"mode": "automatic",
"lightColors": {
"primary": "#007AFF",
"surface": "#FFFFFF"
},
"darkColors": {
"primary": "#0A84FF",
"surface": "#1C1C1E"
}
}
}
Features:
- ✅ Automatic system following - Respects iOS dark/light mode
- ✅ Manual override - Force light or dark mode
- ✅ Complete customization - Define your own colors
- ✅ Professional appearance - iOS-standard styling
📖 Complete Dark/Light Mode Guide - Full theming documentation
🎨 Theme Examples - Ready-to-use configurations
📚 Next Steps
🎯 Essential Guides:
- 🌓 Dark/Light Mode Guide - Complete theming system
- 🧩 UI Components - Product cards, sliders, checkout
- 🛍️ Complete Example - Full shopping app
🔧 Advanced Topics:
- 📡 API Reference - Core functionality
- ⚙️ Configuration - Advanced settings
Join our Discord community or email us at support@reachu.io