Если я правильно прочитал документацию , это то, что вы хотите:
var ref = Firebase(url: MY_FIREBASE_URL)
ref.observeSingleEvent(of: .value) { snapshot in
print(snapshot.childrenCount) // I got the expected number of items
for rest in snapshot.children.allObjects as! [FIRDataSnapshot] {
print(rest.value)
}
}
Лучшим способом может быть:
var ref = Firebase(url: MY_FIREBASE_URL)
ref.observeSingleEvent(of: .value) { snapshot in
print(snapshot.childrenCount) // I got the expected number of items
let enumerator = snapshot.children
while let rest = enumerator.nextObject() as? FIRDataSnapshot {
print(rest.value)
}
}
Первый метод требует, чтобы NSEnumerator
возвращал массив всех объектов, которые затем могут быть перечислены обычным способом. Второй метод получает объекты по одному из NSEnumerator
и, скорее всего, более эффективен.
В любом случае объекты, которые перечислены, являются объектами FIRDataSnapshot
, поэтому вам нужны броски, чтобы вы может получить доступ к свойству value
.
Использование цикла for-in
:
Начиная с написания исходного ответа в Swift 1.2 дня, язык развился. Теперь можно использовать цикл for in
, который напрямую работает с счетчиками вместе с case let
для назначения типа:
var ref = Firebase(url: MY_FIREBASE_URL)
ref.observeSingleEvent(of: .value) { snapshot in
print(snapshot.childrenCount) // I got the expected number of items
for case let rest as FIRDataSnapshot in snapshot.children {
print(rest.value)
}
}
Вот два решения.
1) имеет окружающие двойные кавычки и удаляет символ escape. 2) использует find как есть на пути.
for /f %%a in ('""%systemRoot%\system32\find.exe" /c /v "" < "c:\something.txt""') do @echo %%a
for /f %%a in (' find.exe /c /v "" ^< "c:\something.txt"') do @echo %%a
Это связано с запуском дополнительного процесса cmd для запуска командной строки внутри команды.
Любопытно,
for /f %%a in (' "c:\windows\system32\find.exe" /c /v "" something.txt ') do @echo %%a
Система не может найти указанный путь.
for /f %%a in (' "c:\windows\system32\findstr.exe" /n "." something.txt ') do @echo %%a
Недопустимое имя каталога.
for /f %%a in (' "c:\windows\notepad" "something.txt" ') do @echo %%a
'c: \ windows\notepad "" something.txt "не распознается как внутренняя или внешняя команда, операционная программа или командный файл.
Это последнее дает понять, что внешний
Windows 8.1 32 бит
Я думаю, что проблема с кавычками описана здесь в cmd /?
при вызове дочернего процесса:
If /C or /K is specified, then the remainder of the command line after
the switch is processed as a command line, where the following logic is
used to process quote (") characters:
1. If all of the following conditions are met, then quote characters
on the command line are preserved:
- no /S switch
- exactly two quote characters
- no special characters between the two quote characters,
where special is one of: &<>()@^|
- there are one or more whitespace characters between the
two quote characters
- the string between the two quote characters is the name
of an executable file.
2. Otherwise, old behavior is to see if the first character is
a quote character and if so, strip the leading character and
remove the last quote character on the command line, preserving
any text after the last quote character.
Несколько проще поставить первый токен из инструкции for-loop в токен без кавычек.
for /f "delims=" %%a in (
' if defined OS "C:\my folder with spaces\consoleapp.exe" /param1:"value" '
)do @echo %%a