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 callsNSString.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 andString.init(contentsOfFile:encoding:)
calls it. So, if you know the encoding of the file, useString.init(contentsOfFile:encoding:)
like:If you do not know the string encoding of the file, you may need to implement the functionality by yourself.