) в основном используется для лиц, которые происходят из Objective-C, чтобы чувствовать себя как соглашения Objective-C. Правильно?

я есть класс FileHelper, где я реализовал 3 метода, работа которых заключается в записи содержимого словаря в файл. Эти методы:

func storeDictionary(_ dictionary: Dictionary<String, String>, inFile fileName: String, atDirectory directory: String) -> Bool {
    let ext = "txt"
    let filePath = createFile(fileName, withExtension: ext, atDirectory: directory)
    /**** //If I use this method, file is created and dictionary is saved
    guard (dictionary as NSDictionary).write(to: filePath!, atomically: true) else {
        return false
    }
    */
    guard NSKeyedArchiver.archiveRootObject(dictionary, toFile: (filePath?.absoluteString)!) else {
        return false
    }
    return true
}
func createFile(_ file: String, withExtension ext: String, atDirectory directory: String) -> URL? {
    let directoryPath = createDirectory(directory)
    let filePath = directoryPath?.appendingPathComponent(file).appendingPathExtension(ext)

    if !FileManager.default.fileExists(atPath: (filePath?.absoluteString)!) {
        let success = FileManager.default.createFile(atPath: (filePath?.absoluteString)!, contents: nil, attributes: nil)
        print("\(success)") //** here is the issue I investigated. Always prints false.
    }

    return filePath
}
func createDirectory(_ directory: String) -> URL? {
    let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
    let directoryPath = documentsDirectory.appendingPathComponent(directory)

    do {
        try FileManager.default.createDirectory(at: directoryPath, withIntermediateDirectories: true, attributes: nil)
    } catch let error as NSError {
        fatalError("Error creating directory: \(error.localizedDescription)")
    }
    return directoryPath
}

Когда я звонюFileHelper().storeDictionary(aValidDictionary, inFile: "abc", atDirectory: "XYZ") написать словарь, это не с этой процедурой. Но если я использую

guard (dictionary as NSDictionary).write(to: filePath!, atomically: true) else {
    return false
}

оно работает.

Что случилось сNSKeyedArchiver.archiveRootObject(_:toFile:) метод ??

И почемуFileManager.default.createFile(atPath: (filePath?.absoluteString)!, contents: nil, attributes: nil) всегда возвращает ложь?

Ответы на вопрос(1)

Ваш ответ на вопрос