After deploying my Swift 3 app to Heroku, it crashed with the following error:
fatal error: init(contentsOfFile:usedEncoding:) is not yet implemented: file Foundation/NSString.swift, line 1255
What can I use instead of String.init(contentsOfFile:)
on Ubuntu?
Seeing the latest source code of Swift Standard Library, String.init(contentsOfFile:)
internally calls NSString.init(contentsOfFile:usedEncoding:)
. (NSStringAPI.swift)
And the Linux version of NSString.init(contentsOfFile:usedEncoding:)
, as you see, is not implemented yet. (NSString.swift)
Seems NSString.init(contentsOfFile:encoding:)
is already implemented and String.init(contentsOfFile:encoding:)
calls it. So, if you know the encoding of the file, use String.init(contentsOfFile:encoding:)
like:
let fileContent = try? String(contentsOfFile: filePath, encoding: .utf8)
If you do not know the string encoding of the file, you may need to implement the functionality by yourself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With