user2924482 user2924482 - 15 days ago 6
iOS Question

Swift: reference to generic type Range requires arguments in

I'm trying to create a function to return Range but I'm getting this error:

reference to generic type Range requires arguments in...

This is my code:

func rangOfSubString(msgStr:String) -> Range {

...
}


Any of you knows why or a way to work around this error?

I'll really appreciate your help.

Answer

Range is a generic public struct as is defined here in swift->Collection->Range

public struct Range<Bound : Comparable>
{
  ....
}

so you need to specify the type of data that will have and must implement the comparable protocol, use something like this

func rangOfSubString(msgStr:String) ->Range<String.Index>
{

}

I hope this helps you

Comments