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
3
votes
1 answer

Textview scrollRangeToVisible make range go to top

I am trying to scroll to a specific substring located in the attributedText of a UITextView. When the scrolling is complete, I want the substring to be located at the TOP of the visible textview text. However, I can only get the substring to go to…
rdk
  • 439
  • 3
  • 14
3
votes
1 answer

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

i'm trying to implement Easy Game Center link but i get this error: Cannot convert value of type 'NSRange' (aka 'NSRange') to expected argument type 'Range' (aka 'Range') here is the code: static func unarchive(_ data: Data!) ->…
i6x86
  • 1,557
  • 6
  • 23
  • 42
3
votes
4 answers

Swift : How do I find the position(x,y) of a letter in a UILabel?

I am trying to find the position of a letter in a labelText . The code in Objective C is NSRange range = [@"Good,Morning" rangeOfString:@","]; NSString *prefix = [@"Good,Morning" substringToIndex:range.location]; CGSize size = [prefix…
iPhoneDeveloper
  • 958
  • 1
  • 14
  • 23
3
votes
1 answer

rangeOfCharacterFromSet(characterSet).location not Swift?

Been going bonkers with this one as all samples I find use the NSRange version but in Swift 2 this method returns a Range so no location to test. I know that the result of a not found is {NotFound,0} but don't have a scooby doo how to test for…
Piginhat
  • 131
  • 9
3
votes
1 answer

NSRange `replaceCharactersInRange` crashing app after backspace & entry of new character

I have one textfield, & use shouldChangeCharactersInRange method to get value. Here is my Code: - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{ NSLog(@"Pressing :…
Sneha
  • 880
  • 9
  • 24
3
votes
2 answers

Using character delimiters to find and highlight text in Swift

I previously developed an android app that served as a reference guide to users. It used a sqlite database to store the information. The database stores UTF-8 text without formatting (i.e. bold or underlined) To highlight what sections of text…
Aldo
  • 55
  • 9
3
votes
2 answers

Swift Google search with more than two variables

I'm trying to add a google search to my textfield. I've got it so I can look up one or two variables, but after three it crashes. What do I need to change or add to make it work? Here's my code... func textFieldShouldReturn(textField: UITextField)…
Beth Knight
  • 187
  • 2
  • 15
3
votes
0 answers

Casting a Range to NSRange

Here is where I need to cast it to NSRange for user in tweet.userMentions { let userName = user.keyword if let startIndex = tweetTextLabel.text?.rangeOfString("@")?.startIndex { let range =…
Stefan Scoarta
  • 781
  • 9
  • 21
3
votes
2 answers

substringWithRange works with hard coded string, but not user-input string

When I hard code the string in question and attempt to substringWithRange, it works just fine. But when I take a user input as a char and cast it to NSString, it throws up an NSRange exception. Is it because I am casting a char? This doesn't work: …
BIGGIe
  • 41
  • 4
3
votes
5 answers

Get currently typed word in a UITextView

I want to get the currently typed word in a UITextView. A way to get a completely typed word can be found here UITEXTVIEW: Get the recent word typed in uitextview, however, I want to get the word while it is being typed (no matter where it is typed,…
user3607973
  • 345
  • 1
  • 5
  • 15
3
votes
2 answers

UITextView firstRectForRange not working when there's new line characters in the mix

I'm using this method for converting a NSRange to a CGRect as it relates to a UITextView: - (CGRect)frameOfTextRange:(NSRange)range inTextView:(UITextView *)textView { UITextPosition *beginning = textView.beginningOfDocument; UITextPosition…
Mike S
  • 4,092
  • 5
  • 35
  • 68
3
votes
4 answers

Get the index of a parameter in a NSLocalizedString

This is my NSLocalizedString: "YOUR_INFO" = "%i is the first number, %i the second and %i the third"; Later on, i'm using this string like this: NSString *detailString = [NSString stringWithFormat:NSLocalizedString(@"YOUR_INFO", nil), firstVal,…
Sr.Richie
  • 5,680
  • 5
  • 38
  • 62
3
votes
3 answers

How to split strings into substring start with some characters in ios

I am stuck in finding the solution of splitting the string into substrings. I need some proper logic in which I need to read string starting with some character and it should contain at least 17 characters. e.g. "43 01 08 43 13 01 18 FD 48 6B D1 43…
iCoder
  • 1,298
  • 1
  • 9
  • 25
3
votes
1 answer

Detect Character Tapped in UITextView

I'm using the below code to detect words tapped in a UITextView. This works fine, but I want to detect some special characters, like a ?. ? doesn't show up as part of a word when using UITextGranularityWord and I can't seem to get it to show up when…
glenstorey
  • 5,134
  • 5
  • 39
  • 71
3
votes
2 answers

Get NSRange from NSRegularExpression match

I have an array which contains NSRange elements. Now i can get the last range element of the array using [resultArray lastObject]. When i access the last element, It returns some unknown object. (Which means Unknown class) Now i want to cast the…
Kirubachari
  • 688
  • 11
  • 27