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
1
vote
0 answers

Problem with incorrect NSRange of selected text in NSTextView in function under control of NSText.didChangeNotification

I need to use the length of NSRange of last selection in text (in NSTextView) before the text is changed. For this I am using the Notifications in following way: override func viewDidLoad() { NotificationCenter.default.addObserver(self,…
VYT
  • 1,071
  • 19
  • 35
1
vote
2 answers

How to change font in the string only for the last two characters

I have the string 0.1234 To find the last two characters I use string.suffix(2) if I use NSRange to find this range in attributedString it works well until the string will not be with equals values. if the string would be like 1.1212, nsrange will…
1
vote
0 answers

How can to get string range location in swift?

i have to generate the range of string and get the startLocation of sub string and the last location of sub string. i have converted the swift 2 code into swift 4 and i am getting error. Value of type 'Range?' (aka 'Optional>') has no member…
golu_kumar
  • 231
  • 2
  • 9
1
vote
2 answers

Return substring from attributed string using range in Swift

I am trying to get a substring from a string using the range without luck. Having searched high and low, I can't find a way to do this seemingly straightforward task in Swift. The range is in the form of an NSRange obtained from a delegate…
zztop
  • 701
  • 1
  • 7
  • 20
1
vote
2 answers

Scroll text to specific point in UITextView depending on font size

I want my UITextView to scroll to a specific point (a word, or better a breakpoint: ">>>") when user presses a button outside the textview itself (on iOS). The font size can vary depending on user interaction (i.e. the user can rise or lower font…
Mafradan
  • 23
  • 1
  • 6
1
vote
1 answer

Removing Duplicate Words from a UITextView

having this delegate of UItextview i want to remove tagging words that are already in text with this delegate func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool { if text == " ",let…
user4812550
1
vote
2 answers

Convert Range to swift 3

I am trying to convert this code block to work in swift 3. let grainSize = CGFloat(0.01) let min = CGFloat(-3) let max = CGFloat(3) let range = Range(start: Int(min/grainSize), end: Int(max/grainSize)) The issue I am facing is with…
stktrc
  • 1,599
  • 18
  • 30
1
vote
2 answers

Improve algorithm for finding URLs in a body of text - obj-c

I'm trying to come up with an algorithm to find URLs in a body of text. I currently have the following code (this was my sit down and hack it out code, and I know there has to be a better way): statusText.text = @"http://google.com…
joshholat
  • 3,371
  • 9
  • 39
  • 48
1
vote
2 answers

swift 3 find range of text starting with newline and ending with :

I have a swift 3 string that looks like this: var str:String = "first name: \nkevin\nlast name:\nwilliams" when printed, it looks like this: first name: kevin last name: williams xxx field: 408 878 2125 I want to find the ranges of fields that…
mjpablo23
  • 681
  • 1
  • 7
  • 23
1
vote
1 answer

Highlighting words with TextKit selecting the wrong occurrence of repeated words

I'm actually developing a Quran application in which I'm using TextKit to highlight verses and change their color. Everything is going great but I have a little problem with words that appear multiple times. First of all, my code is: import…
1
vote
2 answers

NSString.rangeOfString returns unusual result with non-latin characters

I need to get the range of two words in a string, for example: ยัฟิแก ไฟหก (this is literally me typing PYABCD WASD) - it's a non-sensical test since I don't speak Thai. //Find all the ranges of each word var words: [String] = [] var ranges:…
glenstorey
  • 5,134
  • 5
  • 39
  • 71
1
vote
0 answers

Fatal Exception: NSInvalidArgumentException -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[1]

I have a UITextField when user enters i'm changing the color of some text. It works fine but i got one crash report in this method. Here is the crash report: Fatal Exception: NSInvalidArgumentException *** -[__NSPlaceholderDictionary…
user2474640
1
vote
1 answer

Sort Array with NSRange in swift both by length and location

I am trying to sort an Array of NSRanges in swift both by length and location: var allranges = [NSRange?]() allranges.append(NSRange(location: 3, length: 5)) allranges.append(NSRange(location: 9, length: 2)) allranges.append(NSRange(location: 9,…
IamMashed
  • 1,811
  • 2
  • 21
  • 32
1
vote
0 answers

How can I get NSRange from UITextView?

Hello I'm trying to calculate NSRange in a my text view. I want to create text reader application but I cannot calculate NSRange value. This below image represents my textView. How can I calculate NSRange…
김지윤
  • 11
  • 1
1
vote
2 answers

rangeOfCharacterFromSet: with numeric set

Hoi! I got a NSString which looks something like this: "$1.00". Always a currency symbol with a value. I format this string to remove the symbol and any non-decimal characters with str = [str stringByTrimmingCharactersInSet:[[NSCharacterSet…