如何检查字典中的键与方法参数中的字符串相同?即在下面的代码中,dictobj是NSMutableDictionary的对象,而对于dictobj中的每个键,我需要与string进行比较.怎么做到这一点?我应该指定NSString的键吗?
-(void)CheckKeyWithString:(NSString *)string
{
//foreach key in NSMutableDictionary
for(id key in dictobj)
{
//Check if key is equal to string
if(key == string)// this is wrong since key is of type id and string is of NSString,Control doesn't come into this line
{
//do some operation
}
}
}
Run Code Online (Sandbox Code Playgroud) 比较顶视图时,第一个{}无法执行.==平等测试失败.
在init,我
[self setCurrentPuzzleView:p1];
Run Code Online (Sandbox Code Playgroud)
后来,我
if ([self currentPuzzleView] == p1) {
NSLog(@"Removing P1 from SuperView");
[p1 removeFromSuperview];
} else {
NSLog(@"Removing P2 from SuperView");
[p2 removeFromSuperview];
}
Run Code Online (Sandbox Code Playgroud)
这是现在应该如何比较观点?我认为==对于指针类型是可以的
if ([self currentPuzzleView] == p1) {
Run Code Online (Sandbox Code Playgroud)
视图之间的关系通过InterfaceBuilder建立,其中每个视图(p1,p2等)都声明为IBOutlet Puzzle1 *p1.