我已经从包含多个属性的对象创建了一个JSON字符串文件。这是对象:
RecipeFile : Codable {
var name: String
var theRecipeIngredients: [String]
var theRecipeSteps: [String]
var theRecipeRating: Int
var theRecipeCategory: String
var theRecipeIndexStrings: String
var theRecipeImage: String?
Run Code Online (Sandbox Code Playgroud)
我使用以下代码创建JSON字符串文件:
let json_encoder = JSONEncoder()
let recipeFileName = recipeToDisplay.name! + UUID().uuidString + ".json"
let exportFilePath = getDocumentsDirectory().appendingPathComponent(recipeFileName)
do {
let jsonData = try json_encoder.encode(exportRecipeFile)
if let jsonString = String(data: jsonData, encoding: .utf8)
{
try jsonString.write(to: exportFilePath, atomically: false, encoding: .utf8)
}
} catch {
print(error.localizedDescription)
}
Run Code Online (Sandbox Code Playgroud)
我将其上传到iCloud Drive。我使用UIDocumentPickerViewController从iCloud驱动器导入了字符串文件。我可以解析导入的文件。但是,当调用func documentPicker(_控制器:UIDocumentPickerViewController,didPickDocumentsAt urls:[URL])时,我在xCode调试区域中收到了此消息(已编辑以删除一些路径信息):
[DocumentManager]无法将所选URL文件的缩略图:/// .....波旁威士忌%20Chocolate%20Walnut%20Pie18D20181-DAFD-499C-9873-7D3E0794C37A.json与收件箱副本文件:/// .....波旁威士忌相关联%20Chocolate%20Walnut%20Pie18D20181-DAFD-499C-9873-7D3E0794C37A.json:Error Domain …