i am pretty new in IOS development and currently learning about basic stuff related to IOS development. I recently see an article about storing your API key in info.plist so that it can store more securely, I followed the instruction but looks like I made a mistake, so what did I do wrong? if there's any good resources please do comment bellow, thanks
How I call my API key in view in swiftUI
var body: some View {
ZStack{
ScrollView{
VStack(spacing:0){
//MARK: Top Content of HomeView
// This view represent a content located on the very top of homeview
HomeViewTopContent()
Text("API KEY : \(Bundle.main.infoDictionary?["API_KEY"] as? String ?? "API KEY GA KE FETCH")")
//MARK: Main content
List{
switch self.ViewState {
case .load:
ListItemShimmer()
case .done:
ForEach(0..<5){_ in
ListItemShimmer()
}
.animation(.linear)
case .failed:
Text("Data not loaded, please do refresh")
}
}
.frame(width: UIScreen.width, height: UIScreen.height)
Spacer()
}
}
}
.frame(width: UIScreen.width, height: UIScreen.height)
.ignoresSafeArea()
}
How I store my API key
Result
In your code, you're looking for "API_KEY"
, but in your Info.plist
, you've defined it as "API Key"
-- note the capitalization difference, underscore, etc. -- it's important that there is an exact match.
Change the key in your Info.plist
to API_KEY
and your code will work as expected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With