<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div class=""><<a href="https://github.com/apple/swift-corelibs-foundation/blob/5f8656628c79bf4df3980efbf45dfb3eebd35766/Foundation/NSScanner.swift#L485-L487" class="">https://github.com/apple/swift-corelibs-foundation/blob/5f8656628c79bf4df3980efbf45dfb3eebd35766/Foundation/NSScanner.swift#L485-L487</a>></div><div class=""><br class=""></div><div class=""></div><div class=""><font face="Courier" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>/// Revised API for avoiding usage of AutoreleasingUnsafeMutablePointer and better Optional usage.</font></div><div class=""><font face="Courier" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>/// - Experiment: This is a draft API currently under consideration for official import into Foundation as a suitable alternative</font></div><div class=""><font face="Courier" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>/// - Note: Since this API is under consideration it may be either removed or revised in the near future</font></div><div class=""><font face="Courier" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>extension Scanner {</font></div><div class=""><font face="Courier" class=""><span class="Apple-tab-span" style="white-space:pre">        </span> public func scanInt() -> Int32?</font></div><div class=""><font face="Courier" class=""><span class="Apple-tab-span" style="white-space:pre">        </span> public func scanInteger() -> Int?</font></div><div class=""><font face="Courier" class=""><span class="Apple-tab-span" style="white-space:pre">        </span> public func scanLongLong() -> Int64?</font></div><div class=""><font face="Courier" class=""><span class="Apple-tab-span" style="white-space:pre">        </span> public func scanUnsignedLongLong() -> UInt64?</font></div><div class=""><font face="Courier" class=""><span class="Apple-tab-span" style="white-space:pre">        </span> public func scanFloat() -> Float?</font></div><div class=""><font face="Courier" class=""><span class="Apple-tab-span" style="white-space:pre">        </span> public func scanDouble() -> Double?</font></div><div class=""><font face="Courier" class=""><span class="Apple-tab-span" style="white-space:pre">        </span> public func scanHexInt() -> UInt32?</font></div><div class=""><font face="Courier" class=""><span class="Apple-tab-span" style="white-space:pre">        </span> public func scanHexLongLong() -> UInt64?</font></div><div class=""><font face="Courier" class=""><span class="Apple-tab-span" style="white-space:pre">        </span> public func scanHexFloat() -> Float?</font></div><div class=""><font face="Courier" class=""><span class="Apple-tab-span" style="white-space:pre">        </span> public func scanHexDouble() -> Double?</font></div><div class=""><font face="Courier" class=""><span class="Apple-tab-span" style="white-space:pre">        </span> public func scanString(string searchString: String) -> String?</font></div><div class=""><font face="Courier" class=""><span class="Apple-tab-span" style="white-space:pre">        </span> public func scanCharactersFromSet(_ set: CharacterSet) -> String?</font></div><div class=""><font face="Courier" class=""><span class="Apple-tab-span" style="white-space:pre">        </span> public func scanUpToString(_ string: String) -> String?</font></div><div class=""><font face="Courier" class=""><span class="Apple-tab-span" style="white-space:pre">        </span> public func scanUpToCharactersFromSet(_ set: CharacterSet) -> String?</font></div><div class=""><font face="Courier" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</font></div><div class=""><br class=""></div><div class="">Foundation issues should be discussed on the <b class="">swift-corelibs-dev</b> list.</div><div class=""><br class=""></div><div class="">-- Ben</div></div><br class=""><div><blockquote type="cite" class=""><div class="">On 30 Nov 2016, at 10:10, Oliver Drobnik via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Working on a function for Foundation’s Scanner I stumbled on this LLVM crash: <a href="https://bugs.swift.org/browse/SR-3295" class="">https://bugs.swift.org/browse/SR-3295</a><div class=""><br class=""></div><div class="">This got me thinking about a workaround and I would like to prose this:</div><div class=""><br class=""></div><div class="">When importing Foundation into Swift 3, all </div><div class=""><br class=""></div><div class=""><b class="">AutoreleasingUnsafeMutablePointer<T?>?</b></div><div class=""><br class=""></div><div class="">should instead be exposed as simple:</div><div class=""><br class=""></div><div class=""><b class="">inout T?</b></div><div class=""><br class=""></div><div class="">e.g.</div><div class=""><br class=""></div><div class=""><b class="">open func scanString(_ string: String, into result: AutoreleasingUnsafeMutablePointer<NSString?>?) -> Bool</b></div><div class=""><br class=""></div><div class="">would become</div><div class=""><br class=""></div><div class=""><b class="">open func scanString(_ string: String, into result: inout String?) -> Bool</b></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">The call would stay exactly the same for normal use cases where you specify a receiving variable:</div><div class=""><br class=""></div><div class=""><b class="">var string: String?</b></div><div class=""><b class="">scanString("=", into: &string)</b></div><div class=""><br class=""></div><div class="">because inout parameters require a &</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">for the use case where you don’t require a receiving parameter, a second method without result parameter would be generated:</div><div class=""><br class=""></div><div class=""><b class="">open func scanString(_ string: String) -> Bool</b></div><div class=""><br class=""></div><div class="">This is necessary because you cannot specify nil or an immutable value for an inout parameter. </div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">A fixit/migration would change calls to</div><div class=""><br class=""></div><div class=""><b class="">scanString(“foo", into result: nil)</b></div><div class=""><br class=""></div><div class="">into</div><div class=""><br class=""></div><div class=""><b class="">scanString(“foo")</b></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">The normal call with receiving variable would stay the same. But the case without return would become more concise.</div><div class=""><br class=""></div><div class="">What do you think?</div><div class=""><br class=""></div><div class="">kind regards</div><div class="">Oliver Drobnik</div></div></div></blockquote></div></body></html>