Simple Swift Package to generate typed resources (via keypath mechanism) in code such as Strings or Images. Inspired by R.swift.
struct SettingsView: View {
var body: some View {
Text(\.settingsDataTitle)
}
}| 🔠 Strings | 🖼️ Images |
|---|---|
| ✅ .xcstrings | ✅ .xcassets |
You can add swift-typed-resources to an Swift Package by adding it as a dependency.
let package = Package(
name: "MyPackage",
platforms: [.iOS(.v15), .macOS(.v13)],
products: [
.library(
name: "MyPackage",
targets: ["MyPackage"]
)
],
dependencies: [
.package(url: "https://github.com/bestK1ngArthur/swift-typed-resources.git", exact: "0.0.6")
],
targets: [
.target(
name: "MyPackage",
dependencies: [
.product(name: "SwiftTypedResources", package: "swift-typed-resources")
],
resources: [.process("Resources")]
)
]
)- Right-click on MyPackage to show Xcode context menu.
- Then select GenerateResources in swift-typed-resources section to generate swift files.
import SwiftTypedResources
public extension TypedStrings {
// MARK: Main
var mainActivity: TypedStringConfig { (key: "Main.Activity", table: "Localizable", bundle: .module) }
var mainAppName: TypedStringConfig { (key: "Main.AppName", table: "Localizable", bundle: .module) }
}import SwiftTypedResources
public extension TypedImages {
// MARK: App Icons
var appIconClassicPreview: TypedImageConfig { (name: "AppIcon-Classic-Preview", bundle: .module) }
var appIconFreshPreview: TypedImageConfig { (name: "AppIcon-Fresh-Preview", bundle: .module) }
}