Swift - Public access level

Introduction

If you want a1 and b1 to be publicly accessible, you need to declare that using the public keyword:

class ClassA {
     public  var a1 = 10
}


class ClassB {
     public var b1 = 20
}

However, you will receive a compiler warning because ClassA has the default internal access, which essentially prevents a1 from being accessed outside the module.

To fix this, make the class public as well:


public  class ClassA {
     public var a1 = 10
}

The ClassA and its property a1 are now accessible outside the module.

Related Topic