标签:swift
在swift 中,如果遍历一个集合,可能就需要用到类型推断
方式一:先把一个确定的集合进行推断,之后在遍历,适合单一的元素类型。
let constraints = self.constraints() as! [NSLayoutConstraint]; var item : NSLayoutConstraint? = nil; for constraint in constraints { if constraint.firstAttribute == attribute && constraint.constant == constant{ item = constraint; break; } } return item;
var item : NSLayoutConstraint? = nil; for constraint in self.constraints() { if constraint is NSLayoutConstraint { if constraint.firstAttribute == attribute && constraint.constant == constant{ item = constraint; break; } } }
标签:swift
原文地址:http://blog.csdn.net/wenluma/article/details/45817893