It might be basic and wrong but after understanding structures I can't understand where to practically put it.
Inside some class call it Main
, I would like to encapsulate a set of variables for dimensions.
I know I can just do :
struct Dimensions{
var w:Int
var h:Int
}
class Main
{
//do things using the structure
}
But since i have a lot of variables and i want it clean , I would like to create a new Swift file and put it inside
So inside a file called Dimensions
or else :
import Foundation
struct Dimensions{
var w:Int
var h:Int
}
then the structure is visible to anyone, without even using the Swift file name.
A few questions to ask :
- It seems like a bad idea - why ?
- How is it different from a
Singeltone
to share data between classes? (value type?) - What is the right place to put the structure outside the Main class to get some clear code ?
- Should I make one file with many not related
Structs
?