Get the extension of a file contained in an NSString

前端 未结 6 1973
[愿得一人]
[愿得一人] 2020-12-08 13:25

I have an NSMutable dictionary that contains file IDs and their filename+extension in the simple form of fileone.doc or filetwo.pdf. I need to determine what type of file it

6条回答
  •  青春惊慌失措
    2020-12-08 13:29

    In Swift 3 you could use an extension:

    extension String {
    
    public func getExtension() -> String? {
    
            let ext = (self as NSString).pathExtension
    
            if ext.isEmpty {
                return nil
            }
    
            return ext
        }
    }
    

提交回复
热议问题