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
2
votes
0 answers

how to convert Range to NSRange in swift 4

This is my swift 3 code: extension String { func nsRange(from range: Range) -> NSRange { let lower = UTF16View.Index(range.lowerBound, within: utf16) let upper = UTF16View.Index(range.upperBound, within: utf16) …
chetan panchal
  • 181
  • 2
  • 11
2
votes
5 answers

Problem with NSRange in Objective-C?

I have a little problem with NSRange, or maybe its just the wrong comman I use. Here is what I want to do. I have a string like this : NSString *mystring = @"/c1blue/c2green/c3yellow/" As you can see there is always a command with a value and that…
eemceebee
  • 2,656
  • 9
  • 39
  • 49
2
votes
2 answers

Attribute the word within a specific range using NSRegularExpression in Swift

I have some pure Html string and some of them has title tags Title. facilities: "Facilities
24-hour security, Barbecue area, Car park, Clubhouse, Function room, Gym, Outdoor swimming pool, Playground, Swimming…
Umit Kaya
  • 5,771
  • 3
  • 38
  • 52
2
votes
2 answers

Calculate range of string from word to end of string in swift

I have an NSMutatableString: var string: String = "Due in %@ (%@) $%@.\nOverdue! Please pay now %@" attributedText = NSMutableAttributedString(string: string, attributes: attributes) How to calculate both the length and starting index from the word…
kevinabraham
  • 1,378
  • 4
  • 28
  • 55
2
votes
3 answers

How to select a text in a textView having a NSRange in Swift?

I have a UITextView where I would like to select a part of the text. I'm trying to use selectedTextRange, unfortunately I get this error: Cannot convert value of type 'NSRange' (aka '_NSRange') to expected argument type 'UITextRange' This is the…
Cue
  • 2,952
  • 3
  • 33
  • 54
2
votes
1 answer

Swift: Sort Array with NSRange

I have an array with some NSRanges and want to sort them depending on their location. var rangeArr = Array() rangeArr.append(NSMakeRange(14, 4)) rangeArr.append(NSMakeRange(1, 3)) rangeArr.append(NSMakeRange(5,…
ixany
  • 5,433
  • 9
  • 41
  • 65
2
votes
1 answer

NSRangeException - cannot remove observer

I am trying to capture images and record video from camera but whenever I dismiss my view with camera I get this error: Terminating app due to uncaught exception 'NSRangeException', reason: 'Cannot remove an observer App.CameraViewController…
Superian007
  • 395
  • 7
  • 25
2
votes
1 answer

lldb throwing error: use of undeclared identifier 'NSMakeRange'

If I pause an app's execution and try this command in the debugger: po NSMakeRange(0, 1) I receive the error: error: use of undeclared identifier 'NSMakeRange' error: 1 errors parsing expression I tried using expr @import Foundation to no avail.
Iulian Onofrei
  • 9,188
  • 10
  • 67
  • 113
2
votes
3 answers

Why range.length value changes for backspace in shouldChangeCharactersInRange delegate methos?

I'm trying to figure out this line which works pretty well for backspace after I restrict user up to 24 characters. But I don't know how it really works. I tried to figure out the value of range.length and it's set to 0 if I insert some characters.…
LC 웃
  • 18,888
  • 9
  • 57
  • 72
2
votes
1 answer

What is the quickest and most code efficient way to pull a number from a NSString?

I have a number of strings like these. The numbers can be infinitely long. 1 13 13121 1389988797 What is the quickest and most code efficient way…
Ethan Allen
  • 14,425
  • 24
  • 101
  • 194
2
votes
2 answers

Objective-C error message while creating NSRange

I try to create an NSRange object in Objective-C on my Mac. Unfortunately it gives me an error message which I cannot solve or debug. NSRange newRange = [data rangeOfData:dataToFind options:kNilOptions …
rookieOC
  • 47
  • 5
2
votes
1 answer

NSRangeException being thrown when creating a subarray using range

This is a very odd error that I'm getting. It's this: 'NSRangeException', reason: '*** -[NSArray subarrayWithRange:]: range {2, 3} extends beyond bounds [0 .. 3]' What I don't understand is that the range (2,3) clearly doesn't extent beyond the…
arc4randall
  • 3,275
  • 3
  • 27
  • 40
2
votes
1 answer

NSRange, Find a word within a paragraph getting wrong results

Ive written a method to highlight a word within a paragraph by sending it an NSString of that word, it was working perfectly until i faced this scenario: When i have this text: Their mother has tried dressing them in other ... When I'm passing…
Mutawe
  • 6,464
  • 3
  • 47
  • 90
2
votes
1 answer

how to get a range to text near a specific word in a NSString?

I have a long NSString e.g. "For performance reasons, a table view data source generally reuses UITableViewCell objects. The table view maintains a queue of cell objects that are marked for reuse. For example, if you were displaying a list that…
user777304
  • 455
  • 2
  • 9
  • 24
2
votes
1 answer

Setting attributedText, NSRangeException error

Trying to set my UIText view's attributed text properties via selection. Almost works. Action to set text with red font color below. This works sometimes, but often gives an error: Terminating app due to uncaught exception 'NSRangeException',…
OWolf
  • 5,012
  • 15
  • 58
  • 93