|
| 1 | +--- |
| 2 | +id: get_started |
| 3 | +title: Get started |
| 4 | +description: How to install Tolgee iOS SDK and basic usage instructions. |
| 5 | +--- |
| 6 | + |
| 7 | +## Platform Support |
| 8 | + |
| 9 | +| Platform | Minimum Version | |
| 10 | +|----------|----------------| |
| 11 | +| iOS | 16.0+ | |
| 12 | +| macOS | 13.0+ | |
| 13 | +| tvOS | 16.0+ | |
| 14 | +| watchOS | 6.0+ | |
| 15 | + |
| 16 | +## Requirements |
| 17 | + |
| 18 | +- **Swift:** 6.0+ |
| 19 | +- **Xcode:** 16.3+ |
| 20 | + |
| 21 | +## Adding the SDK |
| 22 | + |
| 23 | +Add to your `Package.swift`: |
| 24 | + |
| 25 | +```swift |
| 26 | +dependencies: [ |
| 27 | + .package(url: "https://github.com/tolgee/tolgee-mobile-swift-sdk", from: "1.0.0") |
| 28 | +] |
| 29 | +``` |
| 30 | + |
| 31 | +Or through Xcode: |
| 32 | +1. File → Add Package Dependencies... |
| 33 | +2. Enter: `https://github.com/tolgee/tolgee-mobile-swift-sdk` |
| 34 | +3. Choose version and add to your target |
| 35 | + |
| 36 | +## Initialization and configuration |
| 37 | + |
| 38 | +Initialize the SDK with your [CDN URL](/platform/projects_and_organizations/content_delivery), typically in your AppDelegate or similar startup location: |
| 39 | + |
| 40 | +```swift |
| 41 | +import Tolgee |
| 42 | + |
| 43 | +let cdnURL = URL(string: "https://cdn.tolgee.io/your-project-id")! |
| 44 | +Tolgee.shared.initialize(cdn: cdnURL) |
| 45 | +``` |
| 46 | +:::warning |
| 47 | + |
| 48 | +Make sure that the format for your CDN files is set to `Apple SDK` in your Tolgee project developer/cdn settings. |
| 49 | +Learn more about [Tolgee Content Delivery](/platform/projects_and_organizations/content_delivery) feature. |
| 50 | + |
| 51 | +::: |
| 52 | + |
| 53 | +> **TIP**: |
| 54 | +> Refer to our SwiftUI and UIKit [examples](https://github.com/tolgee/tolgee-mobile-swift-sdk/tree/main/Examples) for a complete setup. |
| 55 | +
|
| 56 | + |
| 57 | +You can customize the initialization with additional parameters: |
| 58 | +```swift |
| 59 | +// Initialize with specific language and namespaces |
| 60 | +Tolgee.shared.initialize( |
| 61 | + cdn: URL(string: "https://cdn.tolgee.io/your-project-id")!, |
| 62 | + language: "es", // Force Spanish instead of auto-detection |
| 63 | + namespaces: ["buttons", "errors", "onboarding"], // Organize translations |
| 64 | + enableDebugLogs: true // Enable detailed logging for development |
| 65 | +) |
| 66 | +``` |
| 67 | + |
| 68 | +## Fetching remote translations |
| 69 | +You have to explicitly call the `fetch` method to fetch translations from the CDN. |
| 70 | +```swift |
| 71 | +await Tolgee.shared.remoteFetch() |
| 72 | +``` |
| 73 | + |
| 74 | +## Basic Translation |
| 75 | + |
| 76 | +```swift |
| 77 | +// Simple string translation |
| 78 | +let title = Tolgee.shared.translate("app_title") |
| 79 | + |
| 80 | +// Translation with arguments |
| 81 | +let welcomeMessage = Tolgee.shared.translate("welcome_user", "John") |
| 82 | +let itemCount = Tolgee.shared.translate("items_count", 5) |
| 83 | +let nameAndAge = Tolgee.shared.translate("My name is %@ and I'm %lld years old", "John", 30) |
| 84 | +``` |
| 85 | +> **NOTE:** |
| 86 | +> Strings with multiple pluralized parameters are currently **not supported**, |
| 87 | +> for example `Tolgee.shared.translate("I have %lld apples and %lld oranges", 2, 3)` |
| 88 | +
|
| 89 | +## Thread-safety |
| 90 | + |
| 91 | +Tolgee SDK is designed to be used synchronously on the main actor (except the `fetch` method). Access to the SDK from other actors generally has to be awaited. |
| 92 | + |
| 93 | +```swift |
| 94 | +Task.deattached { |
| 95 | + // notice that the call has to be awaited outside of the main actor |
| 96 | + let str = await Tolgee.shared.translate("key") |
| 97 | +} |
| 98 | +``` |
| 99 | + |
| 100 | +## Next steps |
| 101 | + |
| 102 | +- __SwiftUI compatibility__: Learn how Tolgee iOS SDK works with your SwiftUI code — [SwiftUI](./swiftui.mdx) |
| 103 | +- __NSLocalizedString swizzling__: Learn how to achieve zero config integration by enabling method swizzling — [Swizzling](swizzling.mdx) |
| 104 | +- __Advanced usage__: Tips and tricks for debugging and using the SDK with advanced codebases — [Advanced usage](./advanced.mdx) |
| 105 | + |
| 106 | + |
0 commit comments