- Open your Xcode project.
- Go to File → Add Packages.
- Enter the repository URL of the WeatherSDK:
https://github.com/TiTaTomte/WeatherSDK.git - Select the version you want to install and click Add Package.
Add the dependency to your Package.swift:
dependencies: [
.package(url: "https://github.com/TiTaTomte/WeatherSDK.git", from: "1.0.0")
]
targets: [
.target(
name: "YourApp",
dependencies: ["WeatherSDK"]
)
]import WeatherSDKWeatherSDK.shared.configure(apiKey: "YOUR_API_KEY")- Replace
YOUR_API_KEYwith your valid API key. - You can get an API key from https://www.weatherbit.io.
WeatherSDK.shared.getForecast(for: "Berlin") { weatherVC in
navigationController?.pushViewController(weatherVC, animated: true)
}Implement the WeatherSDKDelegate to handle success or failure:
class MyViewController: UIViewController, WeatherSDKDelegate {
func onFinished(viewController: WeatherViewController) {
print("User tapped on back button. WeatherViewController can be closed now.")
}
func onFinishedWithError() {
print("Failed to load the weather forecast.")
}
}
WeatherSDK.shared.delegate = selfThis guide explains how to use the predefined Style system in the WeatherSDK for consistent design across your app.
Use the following size constants to maintain consistent spacing and layout:
Style.Size.xs // 4pt - Extra Small
Style.Size.s // 8pt - Small
Style.Size.m // 16pt - Medium
Style.Size.l // 24pt - Large
Style.Size.xl // 32pt - Extra Large
Style.Size.xxl // 48pt - Double Extra Large
Style.Size.xxxl // 56pt - Triple Extra Largelet button = UIButton()
button.contentEdgeInsets = UIEdgeInsets(
top: Style.Size.m,
left: Style.Size.l,
bottom: Style.Size.m,
right: Style.Size.l
)Use the predefined color palette to ensure a unified color scheme:
Style.Colors.accent // Primary accent color
Style.Colors.accentHighlighted // Accent color for highlighted states
Style.Colors.textPrimary // Primary text color
Style.Colors.textSecondary // Secondary text color
Style.Colors.textPlaceholder // Placeholder text color
Style.Colors.textBorder // Border and separator color
Style.Colors.background // Background color
Style.Colors.navigationBarBackground // Navigation bar background colorlet label = UILabel()
label.textColor = Style.Colors.textPrimary
view.backgroundColor = Style.Colors.backgroundUse the following fonts for consistent typography throughout the app:
Style.Fonts.h1 // Bold, 28pt - Large Headers
Style.Fonts.h2 // Bold, 20pt - Section Headers
Style.Fonts.title // Bold, 16pt - Titles
Style.Fonts.textRegular // Medium, 16pt - Body Text
Style.Fonts.label // Medium, 12pt - Labels and Captionslet titleLabel = UILabel()
titleLabel.font = Style.Fonts.h1
titleLabel.text = "Today's Forecast"
titleLabel.textColor = Style.Colors.accent