Cannot invoke initializer for type 'Range' with an argument list of type '(start: Str


let greenHex = hex.substring(with: Range<String.Index>(start: hex.index(hex.startIndex, offsetBy: 2), end: hex.index(hex.startIndex, offsetBy: 4)))

This is Swift3.0, hex is a string, but this code throws an error saying that:


Cannot invoke initializer for type 'Range' with an argument list of type '(start: String.Index, end: String.Index)'



Range.init(start:end:) constructor was removed in Swift 3.0 so you initialize a range like follows:

let range = hex.index(hex.startIndex, offsetBy: 2)..<hex.index(hex.startIndex, offsetBy: 4)

which returns a <em>half-open</em> range of type <String.Index>. Then, you can do the following with that:

hex.substring(with: range)


  • Mapbox iOS move attribution Button
  • Value of “String” has no member 'indices' - moving to Swift 3.0
  • calling asynchronous method inside for-loop [duplicate]
  • how to dynamically increase the height of scroll view?
  • Converting scanLocation from utf16 units to character index in NSScanner (Swift)
  • How do I selecting a date range (like onClick but drag/select)
  • SpringSession DefaultCookieSerializer.setJvmRoute works, but HttpServletRequest does not have the jv
  • create ZPL to print a PNG-image with JAVA
  • Extract IP address from HTML document
  • Passing data from C to Java
  • Spannable text is too wide for TextView
  • An unhandled exception of type 'System.StackOverflowException' occurred in .dll
  • How do int-to-string casts work in Go?
  • Special Characters on Console
  • Javascript match doesn't work in IE
  • inserting hex value into mysql
  • How do I write to registers in hardware using Python?
  • Does Perl currently (5.8 and 5.10) make any promises about the order alternations will be used?
  • Matplotlib: Custom colormap with three colors [duplicate]
  • pyspark substring and aggregation
  • remove unicode characters but keep all special and English characters with preg_replace
  • Replace last two characters in column
  • Alamofire and Reachability.swift not working on xCode8-beta5
  • PHPUnit_Framework_TestCase class is not available. Fix… - Makegood , Eclipse
  • Rearranging Cells in UITableView Bug & Saving Changes
  • using conditional logic : check if record exists; if it does, update it, if not, create it
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • Proper way to use connect-multiparty with express.js?
  • python regex in pyparsing
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Android Google Maps API OnLocationChanged only called once
  • apache spark aggregate function using min value
  • How can I remove ASP.NET Designer.cs files?
  • Sorting a 2D array using the second column C++
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?
  • java string with new operator and a literal
  • How can I use threading to 'tick' a timer to be accessed by other threads?