How to create a Strongly Typed Info.plist?

You can easily access info.plist strongly typed by create a struct this way -

struct InfoPlist<T> {
    static func get(for key: String) -> T? {
        return  Bundle.main.infoDictionary?[key] as? T
    }
    
    static subscript(key: String) -> T? {
        return get(for: key)
    }
}

Now you can use above InfoPlist<T> struct like this -

let bundleIdentifier = InfoPlist<String>["CFBundleDisplayName"]

Share Tweet Send
0 Comments
Loading...
You've successfully subscribed to Developer Insider
Great! Next, complete checkout for full access to Developer Insider
Welcome back! You've successfully signed in
Success! Your account is fully activated, you now have access to all content.