Search code examples
swiftfile-permissionsswift3access-controlswift-extensions

Protection level issues when accessing a struct within an extension


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

https://github.com/knutigro/COBezierTableView

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

public extension UIView {

  public struct BezierPoints {

      static var p1 = CGPoint.zero
      static var p2 = CGPoint.zero
      static var p3 = CGPoint.zero
      static var p4 = CGPoint.zero
  }
}

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.


Solution

  • 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.