Swift UI: Missing return in a function expected to return 'some View'

倖福魔咒の 提交于 2019-12-25 01:37:57

问题


As I am conditionally checking, I cannot return "some view" for the func doFavoriteMath.

private func doFavoriteMath(section: Labvalueslist) -> some View {
    for numbers in userData.favoriteIDS {
        if section.id == (numbers) {
            return ItemRow(list: section)
        }
    }
}

var body: some View {
    NavigationView {
        List {
            ForEach(userData.labvaluesUserdata) {section in
                self.doFavoriteMath(section: section)
            }
        }
    }
}

回答1:


There's no need to return an opaque type from your function. It always returns something of type ItemRow, so the return type can be just that.



来源:https://stackoverflow.com/questions/59268923/swift-ui-missing-return-in-a-function-expected-to-return-some-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!