【问题标题】:Expression pattern of type 'String' cannot match values of type 'AVMetadataKey'“String”类型的表达式模式与“AVMetadataKey”类型的值不匹配
【发布时间】:2017-09-07 20:08:48
【问题描述】:

我正在尝试将我的 Swift 3 代码转换为 Swift 4。我收到以下错误消息:

“String”类型的表达式模式与“AVMetadataKey”类型的值不匹配

private extension JukeboxItem.Meta {
mutating func process(metaItem item: AVMetadataItem) {

    switch item.commonKey
    {
    case "title"? :
        title = item.value as? String
    case "albumName"? :
        album = item.value as? String
    case "artist"? :
        artist = item.value as? String
    case "artwork"? :
        processArtwork(fromMetadataItem : item)
    default :
        break
    }
}

【问题讨论】:

    标签: swift4


    【解决方案1】:

    请在commonKey⌘-单击,您将看到参数类型为AVMetadataKey 而不是String

    我们鼓励您阅读文档。这是值得的,您可以在几秒钟内解决这样的问题。

    如果commonKeynil,我添加了一个guard 语句以立即退出该方法。

    private extension JukeboxItem.Meta {
        func process(metaItem item: AVMetadataItem) {
    
            guard let commonKey = item.commonKey else { return }
            switch commonKey 
            {
            case .commonKeyTitle :
                title = item.value as? String
            case .commonKeyAlbumName :
                album = item.value as? String
            case .commonKeyArtist :
                artist = item.value as? String
            case .commonKeyArtwork :
                processArtwork(fromMetadataItem : item)
            default :
                break
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2019-04-06
      • 2018-01-13
      • 1970-01-01
      • 2018-07-15
      • 2017-11-22
      • 1970-01-01
      • 2016-03-02
      • 1970-01-01
      • 2019-01-14
      相关资源
      最近更新 更多