'Should I init a struct or is it valid to get data from non initialize one in Swift?
I have a struct which just contains some static let data. I Use it as storage for cleaner code and separating function parts from static data which is huge ... something like following code:
struct XtraStates {
static let clickMovePlus: [() -> (States.Action)] = [
{.scaleTo(.small).speed(dims.anim.scaleTime)},
{.visibility(.hide).speed(dims.anim.hideTime)},
{.noAction.duration(1)},
{.clickMove},
{.visibility(.show).speed(dims.anim.hideTime)}
]
static let clickMoveForce: [() -> (States.Action)] = [
....
]
static let allMouseEventsActivate: [() -> (States.Action)] = [
{.localClicks(.activate)},
{.localMouseMove(.activate)},
{.globalClicks(.activate)},
{.globalMouseMove(.activate)},
]
//..... And goes on .....
}
I can read data from it by calling XtraStates.clickMovePlus and it works perfectly but I wonder is it a valid way?
does it init itself every time I get any data from it or it will never get initialized?
what will be the difference if I initialize it like
static let xtarStates = XrtaStates()and read data from initialized one?also which method is more efficient in term of Speed And Memory/CPU usage no matter how small it is?
and finally will be any difference if I keep these data in the Class/Struct which use them most of the time?
Thanks
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
