Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot subscript a value of type 'JSON' with an index of type 'STRING'

This was working in Swift2 but now in Swift3 (after automatic conversion) I'm getting an error:

if self.entry["scheduler"] || self.entry["owner"]

Cannot subscript a value of type 'JSON' with an index of type 'STRING'

The values of self.entry["scheduler"] etc. are boolean but I think the issue is the indices, "scheduler" and "owner"

Of course, I reference other indices of self.entry in the exact same way and get no error when I build.

xcode auto updated and I am living in a nightmare.

like image 407
Works for a Living Avatar asked Nov 06 '16 14:11

Works for a Living


1 Answers

Substitute whatever type you're expecting for the .string in the first two lines

let scheduler = self.entry["scheduler"].string
let owner = self.entry["owner"].string

if(scheduler != nil || owner != nil)
{
    // Take care here - scheduler and owner are both optionals
}
like image 72
DavidA Avatar answered Nov 06 '22 04:11

DavidA