String.init (contentsOfFile :) for Linux?

After deploying my Swift 3 application 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 String.init(contentsOfFile:)in Ubuntu?

+4
source share
1 answer

When it sees the latest source code for the Swift standard library, it String.init(contentsOfFile:)internally calls NSString.init(contentsOfFile:usedEncoding:). ( NSStringAPI.swift )

And the version of Linux NSString.init(contentsOfFile:usedEncoding:), as you can see, is not yet implemented. ( NSString.swift )

It seems to be NSString.init(contentsOfFile:encoding:)already implemented and String.init(contentsOfFile:encoding:)calls it. So, if you know the encoding of the file, use String.init(contentsOfFile:encoding:)as:

let fileContent =  try? String(contentsOfFile: filePath, encoding: .utf8)

, .

+9

Source: https://habr.com/ru/post/1664802/


All Articles