A structure used to describe a portion of a series—such as characters in a string or objects in an NSArray object.
Questions tagged [nsrange]
343 questions
4
votes
2 answers
Prevent NSRangeException in subarrayWithRange
I have this code which allows me to pass in an index, and selectively retrieve, a number of images in an array for a certain range length - depending on orientation.
When in portrait the range should be be 20 items per index, and i have 43 items…

joec
- 3,533
- 10
- 60
- 89
4
votes
2 answers
How to set up a tap gesture only for specific ranges of a UILabel in Swift 3
I have an attributed string set to UILabel with multiple underlines , colors like below image
and I know How to setup a tap gesture for whole label (with enabling user interaction) and below is my code for what I have done including setting up…

caldera.sac
- 4,918
- 7
- 37
- 69
4
votes
1 answer
Swift 3; Range 'Out of bounds'
I've just updated Xcode to 8.0 beta 2 and swift 3.0. After updating from swift 2.3 i'm getting a lot of errors.
I have a String-extension that's converting a Range in the "self"-string to a NSRange:
extension String {
func NSRangeFromRange(_…

Wiingaard
- 4,150
- 4
- 35
- 67
4
votes
3 answers
How to use deleteCharactersInRange?
I want do call the method "deleteCharactersInRange" but it doesn't work.
This is an excerpt from Apples Documentation:
Swift
func deleteCharactersInRange(_ aRange: NSRange)
var day = ""
let stringRange:NSRange = NSMakeRange(0, 4)
day…

Codey
- 1,131
- 2
- 15
- 34
4
votes
1 answer
UiTextView move to next character error with emoji
In a UiTextView i have a function to jump to the next character after the caret:
textView.selectedRange = NSMakeRange(textView.selectedRange.location+1,0);
When i have emoticons it doesn't work, i have to it twice.
I was wondering if i can check…
user1620350
4
votes
4 answers
Objective C: NSRange or similar with float?
For some methods I want them to return a range of values (from: 235, to: 245). I did this using NSRange as a return value
- (NSRange)giveMeARangeForMyParameter:(NSString *)myParameter;
This works fine as long as the return value is an integer range…

FrankZp
- 2,022
- 3
- 28
- 41
4
votes
1 answer
NSRange search in UITextView with NSMutableAttributedString slow
I am trying to search through the contents of my attributed UITextView with the following code:
NSRange range = NSMakeRange(0, haystack.length);
range = [haystack rangeOfString:searchText options:NSCaseInsensitiveSearch range:range];
while…

Joseph
- 9,171
- 8
- 41
- 67
4
votes
3 answers
How to get NSRange(s) for a substring in NSString?
NSString *str = @" My name is Mike, I live in California and I work in Texas. Weather in California is nice but in Texas is too hot...";
How can I loop through this NSString and get NSRange for each occurrence of "California", I want the NSRange…

SMA2012
- 161
- 1
- 3
- 9
4
votes
2 answers
Search exact word in NSString
I need to find a word or several words. With this method, however, I find also piece of word.
NSString *searchString = [NSString stringWithFormat:@"%@",searchField.text];
NSRange range = [textString rangeOfString : searchString];
if…

Vins
- 1,814
- 4
- 24
- 40
3
votes
2 answers
Is it possible to do negative loc in the NSMakeRange?
Is it possible to do negative loc in the NSMakeRange?
NSString *string = @"abc";
NSString *myString = [string substringWithRange:NSMakeRange(-1, 1)];

Voloda2
- 12,359
- 18
- 80
- 130
3
votes
2 answers
Problem using NSRange: Index out of bounds
I am trying to detect website URL's in my string and then doing some attribution string stuff like bolding it etc.
My regex is defined as:
static NSRegularExpression *websiteRegularExpression;
static inline NSRegularExpression *…

Sheehan Alam
- 60,111
- 124
- 355
- 556
3
votes
1 answer
Set range of colored text for UISegmentedControl
According to the following documentation (https://developer.apple.com/documentation/uikit/uisegmentedcontrol/1618570-settitletextattributes)
I should be able to add attributes to change how it looks for a particular mode.
…

Joseph Astrahan
- 8,659
- 12
- 83
- 154
3
votes
1 answer
Get range from unicode character symbols. Swift
I use textView(_: shouldChangeTextIn: replacementText:) function to change the input data depending on the situation. I use range, but I can not get the Swift Range when using unicode character symbols (eg ( ͡° ͜ʖ ͡°) ). Please, tell me how it can…

Alexander Khitev
- 6,417
- 13
- 59
- 115
3
votes
1 answer
Check if one NSRange is within another NSRange or interSecting with it in swift ?
if
case 1 : range1 is (5,10) and range2 is (8,0) it should return true.
case 2 : range1 is (5,10) and range2 is (5,4) it should return true.
case 3 if range1 is (5,10) and range2 is (14,20) it should return true.
How to implement a function that…

Aashish Nagar
- 1,207
- 1
- 14
- 30
3
votes
1 answer
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…

user2924482
- 8,380
- 23
- 89
- 173