Questions tagged [nsrange]

A structure used to describe a portion of a series—such as characters in a string or objects in an NSArray object.

343 questions
21
votes
3 answers

How to create a subarray of NSArray using NSRange?

I have an Array with content. as usual it contain 20 objects. I want the same array split into 2 sections in Tableview. I am trying to implement it with NSMake in current array. For example I need get in first tableview section 3 rows and second…
Anton
  • 3,102
  • 2
  • 28
  • 47
20
votes
4 answers

How to get all NSRange of a particular character in a NSString?

I have two NSStrings: orgText and searchLetter. I want to highlight every occurrences of the searchLetter in the orgText with a red color. How can I get the NSRange of all occurrences of the searchLetter ? for eg : suppose: orgText =…
Arun
  • 3,478
  • 8
  • 33
  • 46
20
votes
2 answers

Find Range of substring in NSMutableAttributedString

I have AttributedString with emoji like this " @Mervin tester " Now I need to find a range of Mervin in this attributed String. let attributedString = NSMutableAttributedString(string: " @Mervin tester ") let range = // range for "Mervin" in above…
Ujesh
  • 1,698
  • 2
  • 23
  • 35
18
votes
1 answer

lint Legacy Constructor Violation: (legacy_constructor) NSMakeRange in Swift?

What is the Swift constructor for the code below? NSMakeRange(0, textfield.text!.characters.count)
Blazej SLEBODA
  • 8,936
  • 7
  • 53
  • 93
18
votes
2 answers

Cannot convert value of type 'NSRange' (aka '_NSRange') to expected type 'Range'(aka 'Range')

Getting this error when checking the range for string characters... @objc func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool { let shouldChange = false let text =…
mosaic6
  • 923
  • 3
  • 11
  • 18
18
votes
1 answer

NSMutableRLEArray objectAtIndex:effectiveRange:: Out of bounds

I try to assign attributes to 3 last chars of newClock string, which is @"3:33:23". However I get an error when construct NSRange: NSMutableAttributedString *mas = [[NSMutableAttributedString alloc]initWithString:newClock]; [mas…
Shmidt
  • 16,436
  • 18
  • 88
  • 136
16
votes
2 answers

String, substring, Range, NSRange in Swift 4

I am using the following code to get a String substring from an NSRange: func substring(with nsrange: NSRange) -> String? { guard let range = Range.init(nsrange) else { return nil } let start = UTF16Index(range.lowerBound) let…
koen
  • 5,383
  • 7
  • 50
  • 89
15
votes
3 answers

Cannot convert value of type 'NSRange' (aka '_NSRange') to expected argument type 'Range' (aka 'Range')

I Have a error in my code like "Cannot convert value of type 'NSRange' (aka '_NSRange') to expected argument type 'Range' (aka 'Range')" but I don't know how to solve this please any one help me? Here I post my…
Saravana Kumar B
  • 225
  • 1
  • 2
  • 7
15
votes
3 answers

NSRange: range.location != NSNotFound vs. range.length > 0

I'm going through some older code in one of my apps and fixing up the code in areas that could be potentially problematic. I'm seeing a lot of old code using... NSRange range = //determine range here.... if(range.length > 0) { //do stuff } Is…
MikeS
  • 3,891
  • 6
  • 35
  • 51
14
votes
3 answers

Create an NSRange with a given minimal and maximal value

I have a collection of int64_t values that I need to make an index set out of. I previously have used: NSIndexSet *set = [NSIndexSet indexSetWithRange:NSMakeRange(location, length)]; to make index sets, but this time its unclear to me how I would…
jac300
  • 5,182
  • 14
  • 54
  • 89
12
votes
2 answers

Problem with NSRange

I'm having a problem with NSRange. Here is my code: NSRange range = [[[NSHTTPCookie requestHeaderFieldsWithCookies:[[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:[NSURL URLWithString:cookie]]] objectForKey:@"Cookie"]…
Rudiger
  • 6,749
  • 13
  • 51
  • 102
12
votes
4 answers

swift range greater than lower bound

I need to implement experience filter like this 0 to 2 years 2+ to 4 years How to express it in swift range? Problem is I can't express more than 2 to 4 years. While I can do less than upper bounds. e.g. like this let underTen = 0.0..<10.0 I…
Warif Akhand Rishi
  • 23,920
  • 8
  • 80
  • 107
11
votes
2 answers

Using Range with NSRange in the NSAttributedString API

I'm attempting to determine the indexes of occurrences of a given string in a String, then generate an NSRange using those indexes in order to add attributes to an NSMutableAttributedString. The problem is rangeOfString returns Range but…
Jordan H
  • 52,571
  • 37
  • 201
  • 351
11
votes
1 answer

Get a range from a string

I want to check if a string contains only numerals. I came across this answer written in Objective-C. NSRange range = [myTextField.text rangeOfCharacterFromSet:[NSCharacterSet letterCharacterSet]]; if(range.location == NSNotFound) { // then it…
Isuru
  • 30,617
  • 60
  • 187
  • 303
11
votes
2 answers

NSMutableAttributedStrings - objectAtIndex:effectiveRange:: Out of bounds

I'm trying to add some fancy text to a label, but I've run into some problems with the NSMutableAttributedString class. I was trying to achieve four this: 1. Change font, 2. Underline range, 3. Change range color, 4. Superscript range. This code: -…
425nesp
  • 6,936
  • 9
  • 50
  • 61
1
2
3
22 23