我试图沿着字典迭代,以修剪未经证实的条目.以下Objective-C代码的
Swift 3转换不起作用:
[[self sharingDictionary] enumerateKeysAndObjectsUsingBlock: ^(id key,id obj,BOOL *stop) { SharingElement* element=[[self sharingDictionary] objectForKey:key]; if (!element.confirmed){ dispatch_async(dispatch_get_main_queue(),^{ [element deleteMe]; }); [[self sharingDictionary] performSelector:@selector(removeObjectForKey:) withObject:key afterDelay:.2]; } else{ element.confirmed=NO; }];
所以我尝试以这种方式使用以下紧凑的enumerated()方法:
for (key,element) in self.sharingDictionary.enumerated(){ if (!element.confirmed){ element.deleteMe() self.perform(#selector(self.removeSharingInArray(key:)),with:key,afterDelay:0.2); } else{ element.confirmed=false } }
然而,编译器在处理变量’element’的使用时报告以下错误:
Value of tuple type ‘(key: Int,value: SharingElement)’ has no member
‘confirmed’
像’元素’一样,完整的元组父亲胜过其能力.
是使用enumerated()或在字典处理中的问题,我该如何解决?