#Obfuscate— Compile-time string obfuscation to hide strings from static analysis#previewOnly— Execute code only when running in Xcode Previews#buildConfig— Different values for DEBUG vs RELEASE builds@PublicInit— Generate public memberwise initializer for structs
dependencies: [
.package(url: "https://github.com/Aeastr/SwiftMacros.git", from: "1.0.0")
]import SwiftMacrosNote
Xcode will prompt you to trust macros from this package on first use. Click "Trust & Enable" to proceed.
Hide strings from static analysis tools (strings, hex editors, etc).
let secret = #Obfuscate("MySecretString")With explicit method:
let secret = #Obfuscate("MySecretString", .xor) // default, best
let secret = #Obfuscate("MySecretString", .bitShift) // very good
let secret = #Obfuscate("MySecretString", .reversed) // good
let secret = #Obfuscate("MySecretString", .base64) // moderate
let secret = #Obfuscate("MySecretString", .bytes) // minimalCaution
This is obfuscation, not encryption. It raises the bar from "trivial" to "annoying" — a determined attacker with a debugger will always win. Never use for API keys or secrets.
Execute code only when running in Xcode Previews.
#previewOnly {
viewModel.loadMockData()
}Expands to the ProcessInfo.processInfo.environment["XCODE_RUNNING_FOR_PREVIEWS"] == "1" check.
Different values based on build configuration.
let apiURL = #buildConfig(debug: "http://localhost:3000", release: "https://api.prod.com")
let timeout = #buildConfig(debug: 60, release: 10)Expands to #if DEBUG / #else / #endif.
Generate a public memberwise initializer for structs.
@PublicInit
public struct User {
let id: UUID
let name: String
var isActive: Bool = true
}
// Generates:
// public init(id: UUID, name: String, isActive: Bool = true) { ... }Contributions welcome. Please feel free to submit a Pull Request.
MIT. See LICENSE for details.