Как сделать массив < And > equatable?

попробуйте это

<input type="checkbox" id="myCheck"  onclick="myFunction()">

function myFunction() {
  // Get the checkbox
  var checkBox = document.getElementById("myCheck");
  // Get the output text
  var text = document.getElementById("text");

  // If the checkbox is checked, display the output text
  if (checkBox.checked == true){
    text.style.display = "block";
  } else {
    text.style.display = "none";
  }
}
1
задан Julien 20 January 2019 в 02:33
поделиться

1 ответ

Вы не можете сделать Array<Any> как Equatable или Decodable, потому что оба protocols будут нуждаться в типе Array's Element, чтобы быть Equatable или Decodable, и Any не выполняет это Требование.

Что вы можете сделать, это создать свой собственный заказ class, чтобы выполнить вышеуказанные требования, как указано ниже,

class MyAny: Equatable, Decodable {

    static func == (lhs: MyAny, rhs: MyAny) -> Bool {
        return lhs.id == rhs.id
    }

    var id: Int
}

class Sample: Decodable {

    var something: Array<MyAny>?
}
0
ответ дан Kamran 20 January 2019 в 02:33
поделиться
Другие вопросы по тегам:

Похожие вопросы: