Reputation: 1089
It might sound a trivial question but I am newbie in Swift, I was wondering whether an internal class can have public methods and variables that I would like to use from that class.
Let's say something like this( as example)
internal class myService: InheritService {
public var x : Int32 = 0
public func sum (_ a: Int32, _b: Int32) -> Int32 {
return (a + b)
}}
Can I sue then function sum and variable x from outside?
Thanks in advance
Upvotes: 5
Views: 1983
Reputation: 91711
Although the following code will compile without warnings, it doesn't really make sense as other comments suggest.
internal class Animal {
public let name = "Bob"
}
Therefore, you might want to add a lint rule such as lower_acl_than_parent to your codebase to prevent you from having code like this.
Upvotes: 0
Reputation: 6157
No it can't. Any access modifiers of properties or methods contained in a first class citizen such as a class, struct, protocol or enum will always be overwritten by that of the containing definition.
Think about it this way, if you can't see a dog, how can you check how many legs it has?
struct Dog {
public var legCount: Int = 3
}
Upvotes: 4