У меня есть класс YoutubeAPIClient:
import Foundation
class YoutubeAPIClient {
let apiKey: String?
init?() {
do {
apiKey = try Environment().getValue(for: "YOUTUBE_API_KEY") as? String
} catch {
//TODO: Implement error handling
print(error)
}
}
}
В методе init я пытаюсь инициализировать apiKey, но он говорит:
Constant 'self.apiKey' used before being initialized
Если это поможет, я включил структуру «Код для среды»:
import Foundation
struct Environment {
func getValue(for key: String) throws -> Any {
guard let value = ProcessInfo.processInfo.environment[key] else {
throw GenericError.noValueForKeyInEnvironment
}
return value
}
}