NSKeyValueObservation无效,Swift 4

时间:2017-08-03 00:53:06

标签: ios swift key-value-observing swift4

如果变量在单例的共享实例上发生变化,我应该如何正确设置接收通知?目前,该块永远不会被解雇。

const elements = [
  '<p id="x" required>Content X</p>', 
  '<p id="y" class="y">Content Y</p>',
  '<a href="www.google.com">Google</a>'
];

const parser = new DOMParser();

const result = elements
.map(element => parser.parseFromString(element, "text/html"))
.map(html => html.firstElementChild.children[1].children[0])
.map(child => {
  const nodeName = child.nodeName.toLowerCase();
  const attrs = [...child.attributes]
    .map(attr => {
      if (attr.value === '') {
        return attr.name;
      } else if (attr.value.indexOf('"') > -1) {
        return `${attr.name}='${attr.value}'`;
      } else {
        return `${attr.name}="${attr.value}"`;
      }
    })
    .join(' ');
  
  return [
    `<${nodeName} ${attrs}>`, 
    child.textContent, 
    `</${nodeName}>`
  ];
});

console.log('Result', JSON.stringify(result, null, 4));

1 个答案:

答案 0 :(得分:4)

将'dynamic'关键字添加到shouldFetchDataFromServer的声明中,它应该可以工作。