Attempting to encode variables, including a 2D array of Int with the JSON framework Freddy. The error I receive is obvious, “Cannot convert value of type ‘[[Int]]’ to expected argument type ‘[JSON]’”, but I am not sure the proper way to accomplish encoding myArray by conforming to Freddy.JSONEncodeable. myArray may not always be the same size, in both dimensions.
import UIKit
import Freddy
class MyClass: NSObject, JSONEncodable {
var myArray: [[Int]] = []
var myType:String = ""
var myName:String = ""
public override init() {
super.init()
myName = "Freddy"
myType = "plaid"
myArray = Array(repeating: Array(repeating: 0, count: 7), count: 7)
myArray[0] = [0,0,1,1,1,0,0]
myArray[1] = [0,1,1,1,1,1,0]
myArray[2] = [1,1,1,1,0,0,0]
myArray[3] = [1,1,0,0,0,0,0]
myArray[4] = [1,1,1,1,0,0,0]
myArray[5] = [0,1,1,1,1,1,0]
myArray[6] = [0,0,1,1,1,0,0]
}
//MARK: JSONEncodable
public func toJSON() -> JSON {
let returnDictionary = JSON.dictionary(["type": .string(self.myType),
"name": .string(self.myName),
"myarray": .array(self.myArray)])
return returnDictionary
}
}