gpt4 book ai didi

swift - 参数标签 '(contentsOfFile:)' 与任何可用的重载都不匹配

转载 作者:行者123 更新时间:2023-11-30 12:04:08 25 4
gpt4 key购买 nike

我正在使用新的 iOS 11 标准更新我的应用程序,很多内容已被弃用,现在我遇到了以下错误:“参数标签 '(contentsOfFile:)' 与任何可用的重载都不匹配。

这是有效的代码:

//load plist file
var palermoip: NSArray?
if let path = Bundle.main.path(forResource: "palermoip", ofType: "plist") {
palermoip = NSArray(contentsOfFile: path)
}

谁知道如何修复它?先感谢您 !

最佳答案

我建议使用PropertyListSerializationURL相关API

let url = Bundle.main.url(forResource: "palermoip", withExtension: "plist")!
let data = try! Data(contentsOf:url)
let palermoip = try! PropertyListSerialization.propertyList(from: data, format: nil) as! [[String:Any]] // or [Any] if the array does not contain dictionaries

在 Swift 4 中甚至是 PropertyListDecoder

关于swift - 参数标签 '(contentsOfFile:)' 与任何可用的重载都不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46861164/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com