nsrange

-[__NSCFDictionary rangeOfString:]: unrecognized selector sent to instance

倾然丶 夕夏残阳落幕 提交于 2019-12-25 02:17:03
问题 i know many solutions are available here for this problem but I am stuck on a single line which runs sometime successfully n crashes sometimes, i really dont know why this is happening..... here is my code of posting mail in which i m getting the error -[__NSCFDictionary rangeOfString:]: unrecognized selector sent to instance and here is my code of the method which is called on button pressed. NSString* ingredientLine = [arrayOfIngredientList objectAtIndex:i]; NSArray* split ; NSRange range =

How to get the range of the first line in a string?

断了今生、忘了曾经 提交于 2019-12-24 05:52:13
问题 I would like to change the formatting of the first line of text in an NSTextView (give it a different font size and weight to make it look like a headline). Therefore, I need the range of the first line. One way to go is this: guard let firstLineString = textView.string.components(separatedBy: .newlines).first else { return } let range = NSRange(location: 0, length: firstLineString.count) However, I might be working with quite long texts so it appears to be inefficient to first split the

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

随声附和 提交于 2019-12-24 01:25:30
问题 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 Overdue in swift? so far I have tried: let startIndex = attributedText.string.rangeOfString("Overdue") let range = startIndex..<attributedText.string.finishIndex // Access the substring. let substring = value[range] print(substring) But it doesn't

How to find Multiple NSRange for a string from full string iOS swift

痞子三分冷 提交于 2019-12-23 22:15:14
问题 let fullString = "Hello world, there are \(string(07)) continents and \(string(195)) countries." let range = [NSMakeRange(24,2), NSMakeRange(40,3)] Need to find the NSRange for numbers in the entire full string and there is a possibility that both numbers can be same. Currently hard coding like shown above, the message can be dynamic where hard coding values will be problematic. I have split the strings and try to fetch NSRange since there is a possibility of same value. like stringOne and

Swift 3; Range 'Out of bounds'

限于喜欢 提交于 2019-12-22 08:13:53
问题 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(_ range : Range<String.Index>) -> NSRange { let utf16view = self.utf16 let from = String.UTF16View.Index(range.lowerBound, within: utf16view) let to = String.UTF16View.Index(range.upperBound, within: utf16view) print("to: \(to) from: \(from)") print(self

Unknown escape sequence - Regular expression

夙愿已清 提交于 2019-12-21 19:06:46
问题 I want to validate email text for which I am using RegexKitLite.h . I am doing things as follows : NSString *strEmail = [txtEmail text]; NSRange range = [strEmail rangeOfRegex:@"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"]; NSLog(@"%@",range); For now I am just checking if this works. But I am getting error in second line. Log doesn't say anything. But there is a warning in second line which says : Unknown escape sequence '\.' What might be the

How can I use NSRange with integers to simplify my code?

混江龙づ霸主 提交于 2019-12-21 12:28:22
问题 I've just started learning Objective-C and made a little compass app that will display a direction when it falls into a range of headings. It works just fine, but I wonder if there is a more concise way of writing it using NSRange . After a lot of looking, it seems like NSRange is used more for string functions rather than numbers. I tried to make an instance of NSRange my starting point to make this more concise, I couldn't track down the function that would find if a number falls within an

Cannot convert value of type 'NSRange' (aka '_NSRange') to expected type 'Range<Index>'(aka 'Range<String.CharacterView.Index>')

丶灬走出姿态 提交于 2019-12-21 06:58:23
问题 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 = textField.text var newString = text!.stringByReplacingCharactersInRange(range, withString: string) as? NSString if newString.length > 14{ newString = newString.substringToIndex(14) } textField.text = newString.uppercaseString return shouldChange } 回答1:

Fastest way to get array of NSRange objects for all uppercase letters in an NSString?

ε祈祈猫儿з 提交于 2019-12-21 05:46:13
问题 I need NSRange objects for the position of each uppercase letter in a given NSString for input into a method for a custom attributed string class. There are of course quite a few ways to accomplish this such as rangeOfString:options: with NSRegularExpressionSearch or using RegexKitLite to get each match separately while walking the string. What would be the fastest performing approach to accomplish this task? 回答1: The simplest way is probably to use -rangeOfCharacterFromSet:options:range:

How to get NSRange(s) for a substring in NSString? [duplicate]

浪子不回头ぞ 提交于 2019-12-20 10:57:24
问题 This question already has answers here : How to get all NSRange of a particular character in a NSString? (4 answers) Closed 6 years ago . 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 because I would like to change it's color in the NSAttributed string. NSRange range = NSMakeRange(0,