gpt4 book ai didi

ios - 使用 .copyItemAtPath 时出错

转载 作者:行者123 更新时间:2023-11-29 01:15:49 29 4
gpt4 key购买 nike

我正在尝试将文件 (.plist) 复制到新目录,但收到错误消息:调用中存在额外参数“错误”。我的代码如下。我搜索了苹果的 swift 文档。我猜 .copyItemAtPath 代码发生了变化,我需要使用 throws,但我无法明显地实现 throws。

var folder = NSBundle.mainBundle().pathForResource(folderName, ofType: folderType)

//this is where i get error

NSFileManager.defaultManager().copyItemAtPath(folder, toPath: folderPath, error:nil)
print("Coppied")

最佳答案

使用 Swift2,你需要做这样的事情:

    do{
try NSFileManager.defaultManager().copyItemAtPath(folder, toPath: folderPath)
print("Coppied")
}catch let error as NSError{
print(error.localizedDescription);
}

关于ios - 使用 .copyItemAtPath 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35199166/

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