I wonder if (and guess no) it is possible to have struct in Swift with variation parts? would be something like this:
struct Item {
var selectionNum: Int
var selectionName : String
var itemCase : Int
switch itemCase {
case 0 :
var paramNum: Int
var paramImage: NSImage
case 1 : var paramText: String
}
This would allow to factor many common parameters and just have specific parts depending on the case. It improves code readibility and avoid having elements of struct defined and not used.
WIth the risk because that cannott be checked at compile time.
For those who remember, this existed in Pascal RECORD (aka struct) where such a CASE can be defined at the end of a record (record length is computed on the max length of the CASE items):
RECORD Item {
selectionNum: Integer
selectionName : String
CASE itemCase : Integer OF
0 : (paramNum: Integer
paramImage: Image)
1 : (paramText: String)
END;