の文字列を返す関数があります。しかし、私は自分の関数で初期のリターン機能を使いたいと思っています。このような何か:Swift 3の戻り値の型[String]を持つ関数からの早期戻り3
func fetchPerson() -> [String] {
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else {
return nil
}
.......
.......
}
しかし、私は同じような問題に直面している:
nilの戻り値の型と互換性がありません '[文字列]' 私だけ
return
文を書いてみました
。しかしそれはまた失敗する。何をすべきか?
編集:1
私はちょうど任意の値なしでこの関数から戻って返すようにしたい場合はどのような。この関数の呼び出しが起こった行に戻ってください。次のようなものがあります。
func fetchPerson() -> [String] {
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else {
return //return to the line where function call was made
}
.......
.......
}
戻り空の配列は.. 'FUNC fetchPerson() - > [文字列] { ガードはappDelegate = UIApplication.shared.delegateようにしましょうか! AppDelegate else { return [] 返信[] } –
戻って何の値でも戻したくないのですか? @ EICaptainv2.0 – nayem
fetchPerson()。count> 0かどうかを確認して、さらに作業を進めてください –