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 this

Join

Search articles

Search titles, tags and article content.

    You've successfully subscribed to Developer Insider
    Your account is ready. Welcome to Developer Insider
    Welcome back! You've successfully signed in
    Success! Your account is fully activated, you now have access to all content.