美文网首页
swift 读取本地Json文件,获取版本号

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

作者: _秃头少女_ | 来源:发表于2018-10-25 11:03 被阅读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)"
        }
    

    赏个喜欢😍再走啊~~~

    相关文章

      网友评论

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

          本文链接:https://www.haomeiwen.com/subject/iueqtqtx.html