Is it possible to access a struct from another class?
ex:
class A{
struct structOfClassA {
func returnLetterA () -> String{
return "a"
}
}
}
class B{
let classA = A()
init(){
classA.structOfClassA.returnLetterA // this is what I want to achieve
}
}
how can I access the the struct from Class A() in Class B()?
is there a workaround with this?
Thank you!
The structure in class
Adefines a type (that can be used within the scope of classA), but you need an instance of it to be able to call the member functions of the structure. E.g.:Alternatively, you can let
Bbe a subclass ofA, which gives you access to the typeStructOfClassAfrom the superclass, in which case you could create an instance ofStructOfClassAand access its methodreturnLetterA():