Check If Swift Dictionary Contains No Values?

后端 未结 4 1059
借酒劲吻你
借酒劲吻你 2021-01-02 07:10

So I\'m making a to-do list app, and I want the user to be notified when all of the shopping items have been deleted. I have a dictionary that contains the String:store as a

4条回答
  •  旧巷少年郎
    2021-01-02 07:44

    A functional programming approach:

    let allEmpty = arr.reduce(true) { $0 && $1.1.isEmpty }
    

    If you're not a big fan of implicit closure arguments, you can of course name them:

    let allEmpty = arr.reduce(true) { empty, tuple in empty && tuple.1.isEmpty }
    

提交回复
热议问题