首页 > 解决方案 > 如何在 Swift 中使用 Vision 实现 plist?

问题描述

我正在尝试创建一个程序,该程序使用 Vision 来识别罐装饮料并将名称和咖啡因含量显示在屏幕上的两个 UILabel 中。我在 CreateML 中训练了一个模型来识别 Monster 和 Del's Shandy。我有一个小 plist(用于测试目的)和一些我认为可以显示饮料的代码,但它似乎不起作用。我已经获得了要显示的名称和信心水平,尽管这并不是我想要的。这是我用来尝试访问 plist 的代码:

DispatchQueue.main.sync {
                    if self.productID != nil {
                        guard self.productCatalog[self.productID] != nil else {
                            return
                        }
                        self.outputLabel.text = self.productCatalog[self.productID]?["Name"] as? String
                        self.caffeineContentLabel.text = self.productCatalog[self.productID]?["Caffeine"] as? String

                        
                    }

我以前读plist的字典的方法如下:

    override func awakeFromNib() {
        if let path = Bundle.main.path(forResource: "ProductCatalog", ofType: "plist") {
            productCatalog = NSDictionary(contentsOfFile: path) as? [String: [String: Any]]
        }
    }

标签: iosswiftiphonexcodeplist

解决方案


推荐阅读