【发布时间】:2014-08-28 11:50:33
【问题描述】:
我想知道如何将以下内容转换为 Swift。我已经尝试过了,但陷入了一个概念:
我正在使用我的 attribute UICollectionViewLayoutAttributes 遍历我的所有对象
[newVisibleItems enumerateObjectsUsingBlock:^(UICollectionViewLayoutAttributes *attribute, NSUInteger idx, BOOL *stop) {
UIAttachmentBehavior *spring = [[UIAttachmentBehavior alloc] initWithItem:attribute attachedToAnchor:attribute.center];
spring.length = 0;
spring.frequency = 1.5;
spring.damping = 0.6;
[_animator addBehavior:spring];
[_visibleIndexPaths addObject:attribute.indexPath];
}];
Swift:标记为 * 的变量出现错误:
for (index, attribute) in enumerate(newVisibleIems) {
var spring:UIAttachmentBehavior = UIAttachmentBehavior(item: ***attribute***, attachedToAnchor: attribute.center)
spring.length = 0
spring.frequency = 1.5
spring.damping = 0.6
self.animator.addBehavior(spring)
self.visibleIndexPaths.addObject(attribute.indexPath)
}
***类型“AnyObject”不符合协议“UIDynamicItem”
我认为这是因为我没有告诉项目 attribute 是 UICollectionViewLayoutAttributes。但是不知道怎么写?
本质上,我如何将 Objective C 转换为 Swift?
【问题讨论】:
标签: ios objective-c swift enumerate fast-enumeration