I am trying to initialize a String from the content accessible by a URL:
actualresponse.response = String(contentsOfURL: url, usedEncoding: NSUTF8StringEncoding)
I get the following error thrown, pointing at the usedEncoding:
Cannot convert value of type 'UInt' to expected argument type 'UnsafeMutablePointer'
Can anyone tell me why this error is thrown and how I can fix it?
Best Answer
There are two similar but different methods which can be mistaken.
The usual method is
The
encoding
parameter takes anNSStringEncoding
value to specify the encoding, for exampleThe second method retrieves the encoding from the file by passing a pointer as
usedEncoding
parameterThe documentation says:
That means you have to pass a pointer which will contain the determined encoding of the file.