Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要将 div 中的关键对象与字符串进行比较。for我在循环中访问关键对象:
for
for (id key in _photosDic) { ... }
在循环中,我想将键与字符串进行比较。我必须将密钥转换为字符串吗?
idtype 可以是任何东西,所以第一步是检查它是否真的是 aNSString或不是。
id
NSString
为此,您可以使用它:
if ([idObject isKindOfClass:[NSString class]]) { //Now do a simple casting NSString *myString = (NSString *)idObject; //Now compare the strings NSComparisonResult result = [myOtherString compare:myString]; }