Search code examples
iosswiftextension-methodsaccess-levels

Extension initializer is inaccessible due to 'internal' protection level swift 4


I have a convenience initializer in an extension inside my framework. And I want to use it in another extension in my project. It granted public access to everything I could but the compiler keeps saying "initializer is inaccessible due to 'internal' protection level"...

Here is my extension in framework:

public extension UIColor {
    public convenience init(hex: Int) {
        self.init(red:(hex >> 16) & 0xff, green:(hex >> 8) & 0xff, blue:hex & 0xff)
    }
}

and here is my extension in my project:

import myFramework

extension UIColor {
    class var backgroundGrey: UIColor {
        return UIColor(hex: 0xe3e8eb)
    }
}

The error is when I call UIColor(hex).

Do you know what's wrong here ?

Edit: I added the framework import


Solution

  • Generally the answer here is to clean the project. If that doesn't work, delete DerivedData. If that doesn't work, then start simplifying the project to just do this one thing (import the framework and access the extension), because you have something else in the project interfering.