Swift - Internal access level

Introduction

Assume that you have the following files:

  • ClassA.swift
  • ClassB.swift

ClassA.swift contains the following definition:

class ClassA {
    var a1 = 10
    //same as
    //internal var a1 = 10
}

ClassB.swift contains the following definition:

class ClassB {
    var b1 = 20
    //same as
    //internal var b1 = 20
}

By default, both a1 and b1 have internal access control.

As long as ClassA.swift and ClassB.swift are contained within the same module, a1 is accessible by the code in ClassB, and b1 is accessible by the code in ClassA.

Suppose that ClassA.swift and ClassB.swift are both part of an iPhone application project.

In this case, both a1 and b1 are accessible anywhere within the iPhone project.

Related Topic