FusionPointInc FusionPointInc - 1 year ago 60
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.

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download