How to get the filename from the filepath in swift

后端 未结 10 1508
一生所求
一生所求 2020-12-04 20:47

How to get the filename from the given file path string?

For example if I have a filepath string as

file:///Users/DeveloperTeam/Library/Developer/Co         


        
10条回答
  •  借酒劲吻你
    2020-12-04 21:17

    SWIFT 3.x or SWIFT 4: Shortest and cleanest way of doing this is below. In this example url variable is type of URL in this way we can have a human readable String result of the full file name with extension like My file name.txt and Not like My%20file%20name.txt

    // Result like: My file name.txt
    let fileName = url.lastPathComponent
    

提交回复
热议问题