Ben Sullivan Ben Sullivan - 1 month ago 13x
Swift Question

Protection level issues when accessing a struct within an extension

I am attempting to implement the following library into my project:

To use this, the following properties can be given custom values:

public extension UIView {

public struct BezierPoints {

static var p1 =
static var p2 =
static var p3 =
static var p4 =

In my MainVC this is configured as follows:

UIView.BezierPoints.p1 = CGPoint(...
UIView.BezierPoints.p2 = CGPoint(...
UIView.BezierPoints.p3 = CGPoint(...
UIView.BezierPoints.p4 = CGPoint(...

In the Swift 2.3 demo project there are no errors. In a Swift 3 project I am receiving the error:

"p1 is inaccessible due to 'internal' protection level."

Can someone please shed some light on the issue here, I'm guessing Swift 3 has some new behind the scenes permissions taking over that need to be overridden.


I guess, the extension you are mentioning is not in the same target as your MainVC?

Because p1 etc. don't have a protection level assigned (and the struct is not private), they are automatically internal. That means, that you can only access these properties within the same target.

But that was also the case in earlier versions of Swift. I don't know, why your code ever worked.

You can read more about the different protection levels in documentation.