大佬教程收集整理的这篇文章主要介绍了ios – 如何在循环中执行多个保护语句?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
for user in users { guard let first = user["firstName"] as? String else { print("first name has not been set") conTinue } print(first) guard let last = user["lastName"] as? String else { print("last name has not been set") conTinue } print(last) guard let numbers = user["phonenumbers"] as? NSArray else { print("no phone numbers were found") conTinue } print(numbers) }
如何确保为每个用户执行所有语句?在else块中放置return和break也不起作用.谢谢!
想象一下,警卫声明(用甘道夫的声音说)“如果你不符合这个条件你就不会过去……”
你想在这里做什么可以简单地用if语句完成:
for user in users { if let first = user["firstName"] as? String { print(first) } else { print("first name has not been set") } //Do the same for the other fields }
有一点需要注意的是,guard语句中的guard允许你在guard语句之后访问unwrapped值,因为if let只允许你在下一个块中访问该值.
以上是大佬教程为你收集整理的ios – 如何在循环中执行多个保护语句?全部内容,希望文章能够帮你解决ios – 如何在循环中执行多个保护语句?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。