FusionPointInc FusionPointInc - 6 months ago 32
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{
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.


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