1

I updated sqlite.swift to version 0.11.4, and my compiler repots an error when I create index including two columns.

Before I was using command

try db.run(table.createIndex([column1, column2], unique: true, ifNotExists: true))

After update, it doesn't work anymore. I should use Expressible. But I'm not that advance.

Contextual type 'Expressible' cannot be used with array literal

Could you please give me a hand here?

Thanks!!!

finder
  • 125
  • 1
  • 12

1 Answers1

0

Ok, I figured out the issue. I'm adding it here in case anybody else runs into the issue. In previous versions of Swift you could pass an array to the variadic parameter. With newer versions of Swift, you can't do that anymore. I had to change my code from:

do {
   try db.run(table.createIndex([identifier], ifNotExists: true))
} catch let error {
   Log.e("DB: Unable to create index for identifier.  Error: \(error.localizedDescription)")
}

to:

do {
   try db.run(table.createIndex(identifier, ifNotExists: true))
} catch let error {
   Log.e("DB: Unable to create index for identifier.  Error: \(error.localizedDescription)")
}

If you need to pass multiple parameters, then just separate them with commas.

try db.run(table.createIndex(identifier1, identifier2, identifier3, ifNotExists: true))
TALE
  • 960
  • 13
  • 22