Last active
August 29, 2015 14:14
-
-
Save rafaelks/8e928dda8e0b07525847 to your computer and use it in GitHub Desktop.
Swift: NSRange vs Range <String.Index>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func exportStrings() -> Void { | |
var foo: String = "" | |
var bar: String = "" | |
if let result = result { | |
let rangeFoo = result.rangeOfString("foo:") | |
let rangeBar = result.rangeOfString("?bar=") | |
if let rangeFoo = rangeFoo { | |
if let rangeBar = rangeBar { | |
let indexStartAddress = rangeFoo.endIndex | |
let indexEndAddress = rangeBar.startIndex | |
let indexStartAmount = rangeBar.endIndex | |
let indexEndAmount = result.endIndex | |
foo = result[Range<String.Index>(start: indexStartAddress, end: indexEndAddress)] | |
bar = result[Range<String.Index>(start: indexStartAmount, end: indexEndAmount)] | |
} else { | |
foo = result[Range<String.Index>(start: rangeFoo.endIndex, end: result.endIndex)] | |
} | |
} else { | |
return | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment