指针和整数之间的有序比较

时间:2011-09-25 01:13:32

标签: objective-c xcode macos

- (void) dealloc
{
[_id_list release];
[super dealloc];
}

- (void)update {
CFArrayRef ar = CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly, kCGNullWindowID);
CFDictionaryRef window;
CFIndex i;
CGWindowID wid;

[_id_list release];
_id_list = [[NSMutableArray alloc] init];

for (i=0; i < window =" CFArrayGetValueAtIndex(ar," name =" (NSString*)CFDictionaryGetValue(window," owner_name =" (NSString*)CFDictionaryGetValue(window,");}

对于最后一行,Xcode给出错误:

  • '语义问题:指针和整数之间的有序比较('CFIndex'(又名'long')和'CFDictionaryRef'(又名'const struct __CFDictionary *'))'

并且,特别为此警告:

  • i&lt;窗口

  • '表达式不可分配'

基本上,我正在尝试获取桌面的WindowID(仅限壁纸)。 为什么会这样?

2 个答案:

答案 0 :(得分:2)

此:

for (i=0; i < window =" CFArrayGetValueAtIndex(ar," name =" (NSString*)CFDictionaryGetValue(window," owner_name =" (NSString*)CFDictionaryGetValue(window,");}

没有任何意义。 for循环通常是:

for ( assignment-expr; comparison-expr ; increment-expr )
{
    body-of-for-loop
}

答案 1 :(得分:2)

忽略了for循环中有一些疯狂的事情,编译器抱怨是因为:

CFDictionaryRef window;
CFIndex i;

这一部分:

i < window

将索引(长)与字典进行比较是没有意义的。