简体   繁体   English

我在Xcode for iOS中得到了“枚举类型的隐式转换”警告,我不知道为什么

[英]I am getting an “Implicit conversion from enumeration type” warning in Xcode for iOS and I don't know why

With this code: 使用此代码:

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

I am getting this warning: 我收到这个警告:

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

Can someone explain to me why I am getting this warning and how to fix it? 有人可以向我解释为什么我会收到此警告以及如何解决此问题?

+dataDetectorWithTypes: does claim to take a value from the NSTextCheckingTypes enum rather than NSTextCheckingType, but going by the rest of its documentation it should indeed allow you to specify individual values from the latter enum. +dataDetectorWithTypes:声称从NSTextCheckingTypes枚举而不是NSTextCheckingType中获取值,但是通过其余的文档,它确实允许您从后一个枚举中指定单个值。 I would just add a cast to NSTextCheckingTypes. 我只想添加一个演员到NSTextCheckingTypes。 You might also want to file a bug on the API. 您可能还想在API上提交错误

Look at the docs for this method. 查看此方法的文档。 The first parameter needs to be of type NSTextCheckingTypes . 第一个参数必须是NSTextCheckingTypes类型。 But the value you pass in, NSTextCheckingTypeLink , is of type NSTextCheckingType . 但是您传入的值NSTextCheckingTypeLink的类型为NSTextCheckingType

You need to pass in either NSTextCheckingAllSystemTypes , NSTextCheckingAllCustomTypes , or NSTextCheckingAllTypes . 您需要传入NSTextCheckingAllSystemTypesNSTextCheckingAllCustomTypesNSTextCheckingAllTypes

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. 有人应该向Apple报告。

Further edit: 进一步编辑:

One workaround would be to make use of a cast: 一种解决方法是使用强制转换:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我从Xcode收到此警告? iOS代码似乎很好 - Why am I getting this warning from Xcode? The iOS code seems fine 为什么我在XCode中收到过时的警告 - Why am I getting a deprecated warning in XCode 从枚举类型'UIBarButtonSystemItem'到不同枚举类型'UIBarButtonItemStyle'的隐式转换 - iPad - iOS5 - Implicit conversion from enumeration type 'UIBarButtonSystemItem' to different enumeration type 'UIBarButtonItemStyle' - iPad - iOS5 从枚举类型“UIInterfaceOrientation”到不同枚举类型“UIDeviceOrientation”的隐式转换 - Implicit conversion from enumeration type 'UIInterfaceOrientation' to different enumeration type 'UIDeviceOrientation' 从枚举类型'UIViewAnimationCurve'到不同枚举类型'UIViewAnimationTransition'的隐式转换 - Implicit conversion from enumeration type 'UIViewAnimationCurve' to different enumeration type 'UIViewAnimationTransition' iOS:为什么我在Xcode中得到“未使用的变量”? - iOS : Why am I getting 'Unused variable' in Xcode? 为什么在调试过程中会收到有关从远程iOS设备读取Xcode框架文件的警告? - Why am I getting warnings about Xcode reading framework files from the remote iOS device during debugging? Xcode:我刚遇到一个Apple Mach-O Linker(Id)错误,不知道为什么 - Xcode: I just got an Apple Mach-O Linker (Id) Error and don't know why 为什么我在Xcode中遇到此Parse问题? - Why am I getting this Parse Issue in Xcode? 为什么我收到来自此请求iOS JSON的空响应 - Why am I getting Empty Response from this Request iOS JSON
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM