Everything you need to know about Swift Access Modifiers

open

public

// First.framework – A.swift
open class A {}
// First.framework – B.swift
public class B: A {} // ok
// Second.framework – C.swift
import First
class C: A {} // ok
// Second.framework – D.swift
import First
class D: B {} // error: B cannot be subclassed

internal

// First.framework – A.swift
internal struct A {}

// First.framework – B.swift
A() // ok

// Second.framework – C.swift
import First
A() // error: A is unavailable

fileprivate

private

final

Swift 4, extensions, and a new private access

class A {
private var flag = false
}
extension A {
func isFlagSet() -> Bool {
return flag
// Error in Swift 3
// works fine in Swift 4
}
}

Recap

Further Study

iOS Developer, computer science freak

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Masih Tabrizi

Masih Tabrizi

iOS Developer, computer science freak

More from Medium

Optionals in Swift

UserDefaults in Swift

Mutating Function in Swift

Preventing Invalid Characters from Being Entered in a UITextField