Using an NSString in a switch statement(在 switch 语句中使用 NSString)
问题描述
是否可以在 switch
语句中使用 NSString
?
Is it possible to use an NSString
in a switch
statement?
还是只使用 if
/else if
更好?
Or is it better to just use if
/ else if
?
推荐答案
switch 语句需要整数常量,所以这里不能使用 NSString,所以看来你必须选择 if/else 选项.
switch statement requires integer constants for it cases so NSString cannot be used here, so it seems you have to go for if/else option.
还有一点是你必须使用 isEqualToString: 或 compare: 方法来比较 NSString,所以即使 switch case 允许指针值你也不能使用它们
One more point is you must compare NSStrings using isEqualToString: or compare: method, so even if pointer values have been allowed for switch cases you could not use them anyway
这篇关于在 switch 语句中使用 NSString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 switch 语句中使用 NSString


基础教程推荐
- Android ViewPager:在 ViewPager 中更新屏幕外但缓存的片段 2022-01-01
- 使用 Ryzen 处理器同时运行 WSL2 和 Android Studio 2022-01-01
- 如何使 UINavigationBar 背景透明? 2022-01-01
- LocationClient 与 LocationManager 2022-01-01
- “让"到底是怎么回事?关键字在 Swift 中的作用? 2022-01-01
- 固定小数的Android Money Input 2022-01-01
- Android文本颜色不会改变颜色 2022-01-01
- 在 iOS 上默认是 char 签名还是 unsigned? 2022-01-01
- 如何使用 YouTube API V3? 2022-01-01
- :hover 状态不会在 iOS 上结束 2022-01-01