Swift   发布时间:2022-03-31  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了swift – 可选绑定的命名约定大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

最初阻止我在代码中加入过多可选绑定的一件事是添加了更多变量名称.例如,我通常会写: if bananasInBarrel != nil{ print("We have \(bananasInBarrel!) bananas in the barrel.") } 因为替代方案似乎有点乱: if let safeBananas = bananasInBarrel{ print("We have
最初阻止我在代码中加入过多可选绑定的一件事是添加了更多变量名称.例如,我通常会写:
if bananasInBarrel != nil{
  print("We have \(bananasInBarrel!) bananas in the barrel.")
}

因为替代方案似乎有点乱:

if let safeBananas = bananasInBarrel{
  print("We have \(safeBananas) bananas in the barrel.")
}

那是很多香蕉.我已经看到人们使用类似b的东西作为新的变量名称(在较大的代码块中可能难以阅读),但我想知道是否有一个普遍接受的变量名称样式标准可供使用可选绑定?谢谢阅读.

只需使用相同的名称
if let bananasInBarrel = bananasInBarrel {
  print("We have \(bananasInBarrel) bananas in the barrel.")
}

不要使用匈牙利语表示法 – 如果您使用的是未包装的可选项,编译器会抱怨.

大佬总结

以上是大佬教程为你收集整理的swift – 可选绑定的命名约定全部内容,希望文章能够帮你解决swift – 可选绑定的命名约定所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。