Questions tagged [nsdatadetector]

The NSDataDetector class is a specialized subclass of the NSRegularExpression class designed to match data detectors. It is available in iOS 4.0 and later and available in OS X v10.7 and later. The issues related with NSDataDetector should be tagged with question with related iOS or OS X platforms.

The NSDataDetector class makes it easy to detect URLs inside a string using just a few lines of code. NSDataDetector class can match dates, addresses, links, phone numbers and transit information.

The results of matching content is returned as NSTextCheckingResult objects. However, the NSTextCheckingResult objects returned by NSDataDetector are different from those returned by the base class NSRegularExpression. Results returned by NSDataDetector will be of one of the data detectors types, depending on the type of result being returned, and they will have corresponding properties. For example, results of type NSTextCheckingTypeDate have a date, timeZone, and duration; results of type NSTextCheckingTypeLink have a URL, and so forth.

Source: NSDataDetector Class Reference

Example:

NSError *error = NULL;
NSDataDetector *detector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeLink|NSTextCheckingTypePhoneNumber
                                                          error:&error];

Related Informations:

Related tags:

Related Questions in SO:

65 questions
21
votes
8 answers

Is it possible to detect links within an NSString that have spaces in them with NSDataDetector?

First off, I have no control over the text I am getting. Just wanted to put that out there so you know that I can't change the links. The text I am trying to find links in using NSDataDetector contains the following:

My main item

Ethan Allen
  • 14,425
  • 24
  • 101
  • 194
10
votes
7 answers

Check email with NSDataDetector

I have a string coming from server and want to check whether it contains expressions like phone numbers, mail address and email. I got success in case of phone number and mail address, but not email. I am using NSDataDetector for this purpose. eg …
Nitish
  • 13,845
  • 28
  • 135
  • 263
10
votes
1 answer

NSDataDetector detecting "phone number" text

The easiest way I can explain this problem is with a code sample and its output, but essentially what's happening is NSDataDetector is detecting a phone number within a string that includes the words "phone number". NSError *error =…
Steve Wilford
  • 8,894
  • 5
  • 42
  • 66
9
votes
2 answers

NSDate detection with NSDataDetector

I tried to get a NSDate from a NSString with UNKNOWN format, So I wrote a function like below -(void)dateFromString:(NSString*)string { NSError *error = NULL; NSDataDetector *detector = [NSDataDetector…
Bavan
  • 1,021
  • 1
  • 10
  • 24
8
votes
1 answer

Extract Address from String - Equivalent to NSDataDetector in iOS

In iOS there's a class named NSDataDetector that, for example, let's you pass a text and it will detect if that text contains things like postal addresses, dates, links... In my case, I'm interested in finding a similar tool for Android that let…
Jorge
  • 285
  • 2
  • 10
8
votes
3 answers

Set context date for NSDataDetector

Suppose today is January 20th, 2014. If I use NSDataDetector to extract a date from the string "tomorrow at 4pm", I'll get 2014-01-21T16:00. Great. But, suppose I want NSDataDetector to pretend the current date is January 14th, 2014. This way, when…
andros
  • 153
  • 1
  • 6
7
votes
2 answers

Extracting address elements from a String using NSDataDetector in Swift 3.0

I'm attempting to use NSDataDetector to addresses from a string. I've taken a look at NSHipster's article on NSDataDetector as well as Apple's NSDataDetector documentation. I've got the following method to the point where it'll pull addresses out of…
Adrian
  • 16,233
  • 18
  • 112
  • 180
7
votes
2 answers

Parse address from NSString without NSDataDetector

I have been using NSDataDetector to parse address out of strings and for the most part it does a good job. However on address' similar to this one it does not detect it. 6200 North Evan Blvd Suit 487 Highland UT 84043 Currently I am using this…
Clip
  • 3,018
  • 8
  • 42
  • 77
4
votes
2 answers

Detecting flight info via NSDataDetector's NSTextCheckingTypeTransitInformation is not ever matching anything

Has anyone had any luck using NSDataDetector on iOS to match flight information? It looks really amazingly powerful, except I can't get it to work at all. Here's what I'm trying: NSDataDetector *detector = [NSDataDetector…
snarshad
  • 469
  • 5
  • 9
3
votes
2 answers

Whats inner functinality of nsdata detector In iphone sdk

I got strange results using NSDataDetector and I am looking for insight in how it works. Is it matching against an internal database or is it using any separation algorithm to detect the separate fields in string? Currently, I am using the following…
Srinivas
  • 983
  • 9
  • 21
3
votes
0 answers

Custom style of Address link in UITextView

I'm seeing something odd inside of UITextView. The UITextView is able to detect my address, but I'm not able to style the text, even though I'm able to style phone numbers & web links. See the code below (I've tried tintColor & linkTextAttributes -…
Jeff
  • 1,800
  • 8
  • 30
  • 54
3
votes
4 answers

How to disable magnification in UITextView

I want to get rid of magnification and text selection in UITextView but I need phone number, link and address detectors. I am using -(void)addGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer { if ([gestureRecognizer…
Umang
  • 129
  • 1
  • 3
  • 9
2
votes
1 answer

How can I use a custom NSDataDetector to detect certain regex patterns?

I am currently using NSDataDetectors to find links: -(void)setBodyText { NSString* labelText = [[message valueForKey:@"body"]gtm_stringByUnescapingFromHTML]; NSDataDetector *linkDetector = [NSDataDetector…
Sheehan Alam
  • 60,111
  • 124
  • 355
  • 556
2
votes
0 answers

Date Detection on iOS: How to go about detecting and processing dates on iOS?

First off, the platform I'm working on: Swift 3 + iOS 10.3. What I'm trying to accomplish: A user attempts to type in some text in a text view, which includes a time in some UITextView. For example: "Meeting at 10pm today". Now that I have the…
mayankk2308
  • 901
  • 1
  • 8
  • 14
2
votes
0 answers

Swift : NSDataDetector for multiple dates in a string

I encountered a somewhat not expected result when analysing string for date with NSDataDetector: I admit, lazy me finds it easier to parse that way, rather than trying to pick dates inside the string : it works in most languages, and you need not…
XavBart
  • 21
  • 3
1
2 3 4 5