[swift-users] Implementing String(contentOfUrl:usedEncoding)

Mohit Athwani mohit.athwani at gmail.com
Wed Feb 22 20:05:45 CST 2017


Hello,

I am trying to contribute to open source software for the first time and
saw that in NSString.swift, a convenience initializer was not implemented
so I decided to work on it.

The initializer is:
public convenience init(contentsOf url:URL, usedEncoding enc:
UnsafeMutablePointer<UInt>?) throws

I don't understand why we need the usedEncoding parameter? I understand
that it's a pointer but how do we decide what encoding to use? Do we
default to NSUTF8StringEncoding?

According to documentation:
Upon return, if url is read successfully, contains the encoding used to
interpret the data. For possible values, see NSStringEncoding.

My understanding is that the url would not be readable without knowing the
encoding to be applied?

What do you guys think?

-Mohit
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170222/53820c45/attachment.html>


More information about the swift-users mailing list