gpt4 book ai didi

ios - 展开可选值时意外发现 nil - Plist

转载 作者:可可西里 更新时间:2023-11-01 00:52:55 25 4
gpt4 key购买 nike

我正在尝试使用 swift 从 propriety list 中读取,但我收到此错误,这就是我用来从我的 plist 中读取的代码:

我正在使用的数组:

var recipeNames :[String] = []
var recipeImages :[String] = []
var recipeTime :[String] = []

在 viewDidload 中:

 var path = NSBundle.mainBundle().pathForResource("recipes", ofType: "plist")
var dict = NSDictionary(contentsOfFile: path!)
recipeNames = dict!.objectForKey("name")! as! [String]
recipeImages = dict!.objectForKey("image")! as! [String]
recipeTime = dict!.objectForKey("time")! as! [String]

最佳答案

在你的代码中似乎没有错误,检查 plist 中的数组是否与你的代码中的数组具有相同的命名可能是错误的键。

您可以通过 right-click 检查在 plist 和 Open-as 上然后选择source code

喜欢: objectForKey("name")称为 <key>name</key> objectForKey("image")称为 <key>image</key> objectForKey("time")称为 <key>time</key>

关于ios - 展开可选值时意外发现 nil - Plist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30976108/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com