GeoFire watchBlock在Swift项目中仅被调用一次

时间:2018-09-22 19:02:20

标签: ios swift firebase geofire

这是我简化的GeoFire观察代码: 问题在于,在初始观察时,observeReady仅被调用一次,但是,当输入新键时,observe函数可以正常工作,但是不会调用完成块。

$count_array = array("if", "world"); //words to search for and count

$word_counts = array();
//initialize the array like [word] => 0
foreach($count_array as $w) {
    $word_counts[$w] = 0;
}

$file = fopen('Data.txt', "r");
while(!feof($file))
{
    $line = trim(fgets($file));
    if ($line != "") {
        $OBJ = json_decode($line);
        $words = str_word_count($OBJ->user->text, 1); //return associative array of words

        foreach($words as $w) { //go through the list of returned words
            if (in_array($w, $count_array)) { //if this word is in our $count_array
                $word_counts[$w]++; //count it!
            }
        }
    }
}

foreach($word_counts as $word => $count) {
    echo '<b>' . $word . ' occurance are ' . $count . " times.</b><br />";
}

1 个答案:

答案 0 :(得分:1)

来自Geofire documentation

  

有时候您想知道何时从服务器加载了所有 initial 键的数据以及这些键的对应事件已被触发。

因此,似乎observeReadyWithBlock仅在触发.keyEntered初始集之后才被调用,而不用于后续更新(除非您更改查询)。当然,应该为进入查询范围的每个键调用.keyEntered