How to split filename from file extension in Swift?

前端 未结 21 1955
陌清茗
陌清茗 2020-12-01 03:24

Given the name of a file in the bundle, I want load the file into my Swift app. So I need to use this method:

let soundURL = NSBundle.mainBundle().URLForReso         


        
21条回答
  •  南笙
    南笙 (楼主)
    2020-12-01 03:52

    They got rid of pathExtension for whatever reason.

    let str = "Hello/this/is/a/filepath/file.ext"
    let l = str.componentsSeparatedByString("/")
    let file = l.last?.componentsSeparatedByString(".")[0]
    let ext = l.last?.componentsSeparatedByString(".")[1]
    

提交回复
热议问题