<div dir="ltr">I ended up writing some convenience APIs to perform these conversions along with many other useful SourceKit<->Cocoa conversions like line+column, UTF-8, UTF-16 and String.Index in SourceKitten. It's MIT-licensed so feel free to grab the String extensions from the project yourself: <a href="https://github.com/jpsim/SourceKitten/blob/master/Source/SourceKittenFramework/String+SourceKitten.swift">https://github.com/jpsim/SourceKitten/blob/master/Source/SourceKittenFramework/String+SourceKitten.swift</a><div><br></div><div>That being said, you might have an easier time working with SourceKitten than with with SourceKit directly, since it does a whole lot more, like dynamically resolving+loading which SourceKit to use, caching expensive operations, easier multi-threaded access, generating documentation, etc.</div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, 24 Mar 2017 at 10:59 Tyler Stromberg via swift-dev <<a href="mailto:swift-dev@swift.org">swift-dev@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_msg"><div class="gmail_msg">I'm currently working on integrating SourceKit with a macOS application. AppKit APIs (e.g. NSAttributedString, NSLayoutManager, etc) deal in terms of NSRange (UTF-16 code units?). SourceKit, however, deals in terms of integer offsets and lengths (UTF-8 code units?). Is there a more efficient or easier way to convert back and forth between the two other than doing the index(_:offsetBy:) -> samePosition(in:) dance?</div></div>
_______________________________________________<br class="gmail_msg">
swift-dev mailing list<br class="gmail_msg">
<a href="mailto:swift-dev@swift.org" class="gmail_msg" target="_blank">swift-dev@swift.org</a><br class="gmail_msg">
<a href="https://lists.swift.org/mailman/listinfo/swift-dev" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-dev</a><br class="gmail_msg">
</blockquote></div>