How do I convert String.Encoding.utf8 to Uint?

I have some legacy code that uses the following code:



init?(path: String, delimiter: String = "\n", encoding : UInt = String.Encoding.utf8, chunkSize : Int = 4096) {

.....

self.encoding = encoding

....

let line = NSString(data: buffer as Data, encoding: encoding)


Xcode is telling me that it can't coerce String.Encoding.utf8 to UInt. Yet the NSString takes encoding as a UInt. And I can't find a constant that represents a legal encoding value of utf8 on the Developers web page about allowed encoding values.


Thanks for any help on getting the let line statement above work.

If I understood well how it works, you shoulkd write


UInt = String.Encoding.utf8.rawValue

How about replacing `NSString` to `String`? (And `UInt` to `String.Encoding`, `NSData` to `Data` and so on...)


    init?(path: String, delimiter: String = "\n", encoding: String.Encoding = .utf8, chunkSize: Int = 4096) {
        //...
        self.encoding = encoding
        //...
        let line = String(data: buffer, encoding: encoding)
    }


If you do not have specific reasons to use `NSString`, this sort of change fits for imported APIs and the Standard Library, which would make your code a little more simple and readable.

String is bridged to NSString, so there should be no need to use NSString explicitly anywhere in your Swift code.

How do I convert String.Encoding.utf8 to Uint?
 
 
Q