指针和整数问题之间的比较

han*_*Dev 1 iphone objective-c ios

我有一个条件语句,我需要一些语法帮助:

if (mySegment.selectedSegmentIndex == 0 && [[[dict objectForKey:[keys objectAtIndex:row]] objectAtIndex:0] == 8 ) {
NSLog(@"test");
}
Run Code Online (Sandbox Code Playgroud)

我收到了comparison between a pointer and integer problem警告.我需要一个基于选择段值的条件,然后将其与从字典对象返回的值进行比较.

谢谢你的帮助.

Eim*_*tas 6

NSDictionary对象只能包含NSNumber实例,而不能包含整数等基本标量类型.这就是你收到警告的原因.

请尝试这一行:

if (mySegment.selectedSegmentIndex == 0 && [[[[dict objectForKey:[keys objectAtIndex:row]] objectAtIndex:0] integerValue] == 8 ) {
...
}
Run Code Online (Sandbox Code Playgroud)

请注意,我已经添加了integerValue对从数组返回的on对象的调用.


Gya*_*ani 6

dict值转换为整数然后进行比较

试试这个:

if (mySegment.selectedSegmentIndex == 0 && [[[dict objectForKey:[keys objectAtIndex:row]] objectAtIndex:0]intValue] == 8 ) {
NSLog(@"test");
}
Run Code Online (Sandbox Code Playgroud)