FusionPointInc FusionPointInc - 1 month ago 7
Swift Question

Is it "LEGAL" or USED in real life to place a class/struct inside of a class/struct?

struct Shape{
var length: Float = 0
var width: Float = 0

struct Rectange {
var length = Shape().length
var width = Shape().width

var area: Float{
get{
return length * width
}
}


}
}


I know how to assign values from one struct to a nested struct. I just want to see if this IS USED or "LEGAL" in real life.

Answer

It is definitely used in real life. Apple even recommends this in one of their sample code examples. https://developer.apple.com/library/content/LucidDreams/Introduction/Intro.html