Skip to content

Instantly share code, notes, and snippets.

@delasign
Created November 8, 2024 22:08
Show Gist options
  • Save delasign/18c2a4e5b80b1fbf6854ea14ac049315 to your computer and use it in GitHub Desktop.
Save delasign/18c2a4e5b80b1fbf6854ea14ac049315 to your computer and use it in GitHub Desktop.
Updated gatherLanguageContent for our language coordinator to work with Swift Testing
private func gatherLanguageContent(langugeCode: String) -> UIContent? {
debugPrint("\(LanguageCoordinator.identifier) gatherLanguageContent \(DebuggingIdentifiers.actionOrEventInProgress) Generating Content for : \(langugeCode)")
let path: String?
if isTestEnvironment {
path = Bundle(for: type(of: self)).path(forResource: languageCode, ofType: "json")
} else {
path = Bundle.main.path(forResource: langugeCode, ofType: "json")
}
guard let languageJSON = path else {
debugPrint("\(LanguageCoordinator.identifier) gatherLanguageContent \(DebuggingIdentifiers.actionOrEventFailed) Failed to gather Content: path does nto exist")
return nil
}
do {
let jsondata = try Data(contentsOf: URL(fileURLWithPath: languageJSON), options: .mappedIfSafe)
let data = try JSONDecoder().decode(UIContent.self, from: jsondata)
debugPrint("\(LanguageCoordinator.identifier) gatherLanguageContent \(DebuggingIdentifiers.actionOrEventSucceded) Generated Content for : \(langugeCode)")
return data
} catch {
debugPrint("\(LanguageCoordinator.identifier) gatherLanguageContent \(DebuggingIdentifiers.actionOrEventFailed) Failed to gather Content for : \(langugeCode)")
return nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment