Jacob Caraballo Jacob Caraballo - 1 month ago 5x
iOS Question

Converting Path Extension to Lowercase in Swift

I'm trying to convert a path extension to lowercase in swift. This should be fairly easy, but when I use the obvious code, I keep getting an error:

var filePath = "/path/to/file.CSV"
var fileExtension = filePath.pathExtension
fileExtension.lowercaseString //ERROR happens when I try to convert to lowercase

error is the following:

execution failed: error: Execution was interrupted, reason:
EXC_BAD_ACCESS (code=1, address=0x0).
The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression
* thread #1: tid = 0x231209, 0x00000001083083a6, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1,
* frame #0: 0x00000001083083a6

When I convert any other string to lowercase, it's completely fine.

My workaround has been to just convert the filePath to lowercase before getting the extension, but I just wanted to know if anyone else is having this issue?


This is a bug for me as well, one work around is to cast the String to NSString like:

var filePath = "/path/to/file.CSV"
var fileExtension = filePath.pathExtension
(fileExtension as NSString).lowercaseString