I'm trying to write some code for seeding some test data into the Core Data database in an application I'm developing, about Pokémon. My code for seeding is based on this: http://www.andrewcbancroft.com/2015/02/25/using-swift-to-seed-a-core-data-database/
I am having a slight problem with one thing though. I don't seem to be able to put a nil value inside of a tuple.
I'm currently trying to seed some Pokémon Moves into the database. A move can have a bunch of different properties, but which combination it has it entirely dependent on the move itself. All seed Move data is in an array of tuples.
To demonstrate...
let moves = [
(name: "Absorb", moveType: grass!, category: "Special", power: 20, accuracy: 100, powerpoints: 25, effect: "User recovers half the HP inflicted on opponent", speedPriority: 0),
// Snip
]
...is fine. It's a move with all the above properties, where zero in speedPriority means something. However, some moves don't have a power or accuracy property, because they're irrelevant to that specific move. However, creating a second tuple in the array without the power or accuracy named elements, such as...
(name: "Acupressure", moveType: normal!, category: "Status", powerpoints: 30, effect: "Sharply raises a random stat", speedPriority: 0)
...understandably throws an error
Tuple types {firstTuple} and {secondTuple} have a different number of elements (8 vs. 6)
because, well, the tuples have different number of elements. So instead, I tried...
(name: "Acupressure", moveType: normal!, category: "Status", power: nil, accuracy: nil, powerpoints: 30, effect: "Sharply raises a random stat", speedPriority: 0)
but this also didn't work, as it gave the error:
Type 'Int' does not conform to protocol 'NilLiteralConvertible'
So, is there any way to do what I'm trying to do? Is there some way to either place a nil value inside the tuple, or somehow make it an optional element? With thanks!