In Objective-c we create range by using NSRange
NSRange range;
So how to create range in Swift?
I created the following extension:
extension String {
func substring(from from:Int, to:Int) -> String? {
if from=0 && to
example of use:
print("abcde".substring(from: 1, to: 10)) //nil
print("abcde".substring(from: 2, to: 4)) //Optional("cd")
print("abcde".substring(from: 1, to: 0)) //nil
print("abcde".substring(from: 1, to: 1)) //nil
print("abcde".substring(from: -1, to: 1)) //nil