3

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

The Windwaker
  • 1,054
  • 12
  • 24
  • Did you import your framework in the file your calling this from? – inokey Sep 12 '18 at 13:27
  • yes sorry, I'll update the question – The Windwaker Sep 12 '18 at 14:33
  • 1
    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. – Rob Napier Sep 12 '18 at 18:02
  • @RobNapier. I had to removed derived data! I didn't do it for so long I forgot this can be an answer to every Xcode problem along with restart Xcode and clean the project. Can you post your comment as an answer so I can tick it ? – The Windwaker Sep 13 '18 at 21:04

1 Answers1

6

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.

Rob Napier
  • 286,113
  • 34
  • 456
  • 610