代码之家  ›  专栏  ›  技术社区  ›  Annabelle Sykes

Uber API编译错误

  •  1
  • Annabelle Sykes  · 技术社区  · 7 年前

    我正在安装iOS版的Uber API(Swift)。然而,我在Codeable+Uber中遇到了以下错误。以下代码块上的swift文件:

    使用未声明的类型“JSONDecoder”

    extension JSONDecoder {
        /// JSON Decoder tailored to the Uber API JSON
        public static var uberDecoder: JSONDecoder {
            let decoder = JSONDecoder()
            decoder.dateDecodingStrategy = .secondsSince1970
            return decoder
        }
    }
    
    2 回复  |  直到 7 年前
        1
  •  0
  •   rmaddy    7 年前

    JSONDecoder 在Swift 4/Xcode 9.0中添加。因为您使用的是Swift 3/Xcode 8,所以会出现错误

    从7月开始,所有应用程序都必须使用Xcode 9和iOS 11的基本SDK。

    最好随时了解最新情况。

        2
  •  0
  •   Ivan Smetanin    7 年前

    那是因为没有 import Foundation .加上 进口基金会 排在第一位。

    更新代码:

    import Foundation
    
    extension JSONDecoder {
        /// JSON Decoder tailored to the Uber API JSON
        public static var uberDecoder: JSONDecoder {
            let decoder = JSONDecoder()
            decoder.dateDecodingStrategy = .secondsSince1970
            return decoder
        }
    }
    

    或者你使用的是Swift 3或更低版本。然后你需要更新Xcode。