swift 读取本地Json文件,获取版本号

2018-10-25  本文已影响23人  _秃头少女_
/// 获取配置信息
///
/// - Parameter resource: 资源文件名
/// - Returns: content
func getConfiguration(resource: String) -> Any {
    if let path = Bundle.main.path(forResource: resource, ofType: "json") {
        do {
            let data = try Data(contentsOf: URL(fileURLWithPath: path), options: .mappedIfSafe)
            let jsonResult = try JSONSerialization.jsonObject(with: data, options: .mutableLeaves)
            return jsonResult
        } catch {
            // maybe lets throw error here
            return []
        }
    }
    return []
    func appVersion() -> String {
        guard let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String, let bundle = Bundle.main.infoDictionary?["CFBundleVersion"] as? String  else {
            return ""
        }
        return  "\(version):\(bundle)"
    }

赏个喜欢😍再走啊~~~

上一篇 下一篇

猜你喜欢

热点阅读