Search code examples
iosswiftxcodeswift-extensions

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:

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!


Solution

  • I found this in 3 Swift files at the end of my code:

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

    So I saw that the code was redeclaring class UIImage after the extension UIImage. In each case, I moved the private func into the extension UIImage and removed the class UIImage from the code. This removed all of the 'UIImage' is ambiguous for type lookup in this context errors throughout my project.