我试图沿着字典迭代,以修剪未经证实的条目.以下Objective-C代码的
Swift 3转换不起作用:
是使用enumerated()或在字典处理中的问题,我该如何解决?
原文链接:https://www.f2er.com/swift/319345.html[[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; }];@H_403_3@所以我尝试以这种方式使用以下紧凑的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 } }@H_403_3@然而,编译器在处理变量’element’的使用时报告以下错误:
@H_403_3@Value of tuple type ‘(key: Int,value: SharingElement)’ has no member@H_403_3@像’元素’一样,完整的元组父亲胜过其能力.
‘confirmed’
是使用enumerated()或在字典处理中的问题,我该如何解决?