6

使用此代码:

NSDataDetector *detector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeLink
                                                               error:&error];

我收到此警告:

Implicit conversion from enumeration type 'enum NSTextCheckingType' to different enumeration type 'NSTextCheckingTypes' (aka 'enum NSTextCheckingTypes')

有人可以向我解释为什么我会收到此警告以及如何解决它吗?

4

2 回答 2

9

+dataDetectorWithTypes:确实声称从 NSTextCheckingTypes 枚举而不是 NSTextCheckingType 中获取一个值,但是按照其文档的其余部分,它确实应该允许您从后一个枚举中指定单个值。我只想为 NSTextCheckingTypes 添加一个演员表。您可能还想在 API 上提交错误。

于 2013-01-09T00:18:15.497 回答
5

Look at the docs for this method. The first parameter needs to be of type NSTextCheckingTypes. But the value you pass in, NSTextCheckingTypeLink, is of type NSTextCheckingType.

You need to pass in either NSTextCheckingAllSystemTypes, NSTextCheckingAllCustomTypes, or NSTextCheckingAllTypes.

Edit:

Upon further review, while what I stated seems correct from a parameter point of view, the rest of the docs for the method claim something else that contradicts the parameter type. Either something changed or this is a bug. Someone should report this to Apple.

Further edit:

One workaround would be to make use of a cast:

NSDataDetector *detector = 
    [NSDataDetector dataDetectorWithTypes:(NSTextCheckingTypes)NSTextCheckingTypeLink
    error:&error];
于 2013-01-09T00:16:20.497 回答