NSDataDetector,字符串中检测URL

NSDataDetector *detector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeLink error:&error];
NSArray *matches = [detector matchesInString:textString options:0 range:NSMakeRange(0, textString.length)];
for (NSTextCheckingResult *match in matches) {
    if ([match resultType] == NSTextCheckingTypeLink) {
        NSRange matchRange = [match range];
	NSURL *url = [match URL];
    }
}

你可能感兴趣的:(ios,NSDataDetector)