Search code examples
swiftxcodedatepickertvos

Getting initializer is inaccessible due to 'internal' protection level


I know this may not be the right place to ask this particular question, but I've tried contacting the author of the GitHub repository below, and there has been no response so far.

So, I've found this particularly useful library on GitHub, which essentially allows for the creation of one or more 'pickers' on tvOS. It comes with a handy pre-made date picker, which uses a MultiPickerConfiguration class to handle UI configuration amongst other properties.

However, after pulling in the library via Cocoapods, I seem unable to instantiate my own MultiPickerConfiguration object. I've tried creating a new initializer via an extension, but Xcode complains with the following message:

initializer is inaccessible due to 'internal' protection level

I'm kinda stumped at this point, and I would really like not to have to pull in the entire .xcproj into my .xcworkspace.

Does anyone have any suggestions? Thank you!


Solution

  • The struct needs a public init method. Either the author needs to add one or you could ad one and submit it as a pull request.

    The default memberwise initializer for a structure type is considered private if any of the structure’s stored properties are private. Likewise, if any of the structure’s stored properties are file private, the initializer is file private. Otherwise, the initializer has an access level of internal.

    As with the default initializer above, if you want a public structure type to be initializable with a memberwise initializer when used in another module, you must provide a public memberwise initializer yourself as part of the type’s definition.

    https://docs.swift.org/swift-book/LanguageGuide/AccessControl.html#ID21