本文介绍了在switch语句中使用NSString的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在switch
语句中使用NSString
?
Is it possible to use an NSString
in a switch
statement?
还是只使用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,因此,即使在切换情况下允许使用指针值,您也无法使用它们
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!