简体   繁体   English

Swift 5 错误:“UIImage”在此上下文中的类型查找不明确

[英]Swift 5 Error: 'UIImage' is ambiguous for type lookup in this context

When I try to create a UIImage extension in Swift 5, like this:当我尝试在 Swift 5 中创建 UIImage 扩展时,如下所示:

extension UIImage {  
}

I get this error:我收到此错误:

'UIImage' is ambiguous for type lookup in this context

What causes this and how do I avert it?这是什么原因造成的,我该如何避免? Thanks!谢谢!

I found this in 3 Swift files at the end of my code:我在代码末尾的 3 个 Swift 文件中找到了这个:

class UIImage {
    private func newBorderMask(_ borderSize: Int, size: CGSize) -> CGImageRef? {
    } 
}

So I saw that the code was redeclaring class UIImage after the extension UIImage .所以我看到代码在extension UIImage之后重新声明了class UIImage extension UIImage In each case, I moved the private func into the extension UIImage and removed the class UIImage from the code.在每种情况下,我都将private func移到extension UIImage并从代码中删除了class UIImage This removed all of the 'UIImage' is ambiguous for type lookup in this context errors throughout my project.这删除了所有'UIImage' is ambiguous for type lookup in this context整个项目'UIImage' is ambiguous for type lookup in this context错误中的'UIImage' is ambiguous for type lookup in this context

You need你需要

import UIKit

at the top of the file在文件顶部

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

相关问题 在这种情况下,“错误”对于类型查找是模棱两可的 - 'Error' is ambiguous for type lookup in this context Multipeer Connectivity 在这种情况下,Xcode 8 beta 'Error' 对于类型查找是不明确的 - Xcode 8 beta 'Error' is ambiguous for type lookup in this context 错误:“事务”对于此上下文中的类型查找不明确 - Error: 'Transaction' is ambiguous for type lookup in this context Swift 3:表达式类型[UIImage]在没有更多上下文的情况下是模棱两可的 - Swift 3: Expression type [UIImage] is ambiguous without more context 在这种情况下,“ CompletionHandler”对于类型查找是不明确的 - 'CompletionHandler' is ambiguous for type lookup in this context 在这种情况下,“类”对于类型查找是模棱两可的 - 'Class' is ambiguous for type lookup in this context 在这种情况下,“ JSONEncoder” /“ JSONDecoder”对于类型查找是不明确的 - 'JSONEncoder' / 'JSONDecoder' is ambiguous for type lookup in this context “对象”对于 Xcode 9 中此上下文中的类型查找不明确 - 'Object' is ambiguous for type lookup in this context in Xcode 9 Swift 错误 - 表达式类型不明确,没有更多上下文 - Swift Error - Type of expression is ambiguous without more context 表达式类型 '@lvalue UIImage?' 在没有更多上下文的情况下是模棱两可的 - Expression type '@lvalue UIImage?' is ambiguous without more context
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM