我正在尝试在我的Xcode配置文件中获取特定值。
因此,如果我在上面的示例中打印项目0,我知道部分代码是print(Bundle.main.infoDictionary["Fonts provided by application"])
。但是,如果我添加["Item 0"]
,它不起作用。
我该如何解决这个问题?如果"Fonts provided by application"
键是Dictionary
类型,我该怎么做?
"UIAppFonts"
,而不是"Fonts provided by application"
。后者只是Xcode中显示的显示。Bundle.main.infoDictionary["UIAppFonts"]
的结果是一个数组,而不是另一个字典。因此,您可以像访问任何其他数组一样访问数组的每个元素。例:
if let fonts = Bundle.main.infoDictionary["UIAppFonts"] as? [String] {
// List all of the fonts
for font in fonts {
print(font)
}
// Get the first font
let font = fonts[0]
// or more safely
if let font = fonts.first {
}
}
Info.Plist是一本字典。因此,要访问您可以使用的字体数组
Bundle.main.infoDictionary["Fonts provided by application"]
但是要访问您需要使用的每个元素
(Bundle.main.infoDictionary["Fonts provided by application"] as? Array)?.startIndex