実行環境
- macOS
- Swift 5
実現したいこと
retun
の上と isState=true
の下で print()
を実行すると、
return -> if 文内の処理、の順に実行されていました。
なので、関数を実行すると先に false
が返されます。
なぜ先に return
されるのでしょうか?
※Firestoreのドキュメントは取得できています。
該当のソースコード
Swift
1func sample() -> Bool { 2 var isState: Bool = false 3 Firestore.firestore().collection("").document("").getDocument{(doc, err) in { 4 if let doc = doc, doc.exists { 5 isState = true 6 } else { 7 isState = false 8 } 9 } 10 return isState 11}
試したこと
- Firestore の処理を無くし実行すると、きちんと
true
が返された。
回答1件
あなたの回答
tips
プレビュー