Last active
August 29, 2015 14:19
-
-
Save erica/b0127c80e07da963b3aa to your computer and use it in GitHub Desktop.
Stupid Reflection Tricks
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
// My evil | |
extension Range { | |
var NSRangeValue : NSRange { | |
let location = reflect(startIndex).summary.toInt() ?? 0 | |
let length = reflect(distance(startIndex, endIndex)).summary.toInt() ?? 0 | |
return NSMakeRange(location, length) | |
} | |
} | |
let testString = "abcdefghij" | |
var range = testString.rangeOfString("cde", options: .CaseInsensitiveSearch, range: nil, locale: nil)! | |
(testString as NSString).substringWithRange(range.NSRangeValue) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment