appendingPathComponent'不可用:在URL上使用appendingPathComponent而不是.a

时间:2017-12-20 02:55:48

标签: ios swift

我使用的是Swift 4,Xcode 9和开发目标iOS 11.0。

我正在尝试将自定义文件夹(MyFolder)附加到path变量。

let outputFilePath = (NSTemporaryDirectory() as NSString).appending("MyFolder").appendingPathComponent((outputFileName as NSString).appendingPathExtension("mov")!)

但是构建器正在给出错误消息:

  

appendingPathComponent'不可用:改为在URL上使用appendingPathComponent。

我知道,我在做一些愚蠢的错误。你能帮助我吗?

2 个答案:

答案 0 :(得分:0)

请检查以下代码,以便在文档目录

中参考
//name for file to be added 
let uuid = UUID().uuidString
// storing a Audio File in Directory 
let audioFilename = getDocumentsDirectory().appendingPathComponent("\(uuid).m4a")

在文件夹中附加文件您可以使用此

    //This function returns a Array with file names Available
    class func getListOfRecordingsAvailable() -> [String] {
            var fileNameArray = [String]()
            let documentDirectoryPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first!
            let myFilesPath = documentDirectoryPath.appending("/FolderName")
            let files = FileManager.default.enumerator(atPath: myFilesPath)

            while let file = files?.nextObject() {
                //myfilesPath - Path
                //file - fileName
                fileNameArray.append(file as! String)
            }

            print(fileNameArray)
            return fileNameArray


}

获取所创建的尊重文件夹中可用文件的名称

Sub CalculateStats_Click()

    Dim i As Integer
    Dim x As Integer

    'start row specified below as i
    i = 12
    'stop row specified as x
    x = 94

    Dim startloc As String
    Dim stoploc As String
    Dim reportcol As Integer


    Range("A11").End(xlToLeft).Select
    ActiveCell.Offset(0, 1).Select
    ActiveCell = Date
    reportcol = ActiveCell.Column

    Do While i < x
        startloc = "H" & i
        stoploc = "I" & i
        Cells(i, reportcol).Value = WorksheetFunction.Sum(Worksheets("Analysts").Range(Worksheets("Analysts").Range(startloc), Worksheets("Analysts").Range(stoploc)))
        i = i + 1
    Loop

End Sub

答案 1 :(得分:0)

使用此行

URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("MyFolder").appendingPathComponent(outputFileName).appendingPathExtension("mov")

而不是

(NSTemporaryDirectory() as NSString).appending("MyFolder").appendingPathComponent((outputFileName as NSString).appendingPathExtension("mov")!)

这会返回url并使用url.Pathstring中获取其路径。 希望这会对你有所帮助。