Cannot index a value of type "JSON" with an index of type "STRING"

This worked in Swift2, but now in Swift3 (after automatic conversion) I get an error message:

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

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

Self.entry ["scheduler"] values, etc. are logical, but I think the problem is the indices, the "scheduler" and the "owner"

Of course, I refer to other self.entry indexes in the same way and get no errors when building.

xcode updates automatically and I live in a nightmare.

+7
swift3 swifty-json
source share
1 answer

Replace whatever type you expect for .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 } 
+11
source share

All Articles