Обновлено до xcode7-beta Я сталкиваюсь с новым видом предупреждения. Вот мой кодПеременная «xxx» никогда не была мутировалась, подумайте об изменении «let»
override func layoutAttributesForElementsInRect(rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
var attributes: [UICollectionViewLayoutAttributes]? = super.layoutAttributesForElementsInRect(rect)
if let layoutInfo = self.layoutInfo {
attributes?.append(layoutInfo)
}
return attributes
}
предупреждающее сообщение Variable 'attributes' was never mutated, consider changing to 'let' constant
Почему Xcode говорят Variable 'attributes' was never mutated
?
Вопрос Update
предупреждение исчезает, когда я изменить свой код на этот
override func layoutAttributesForElementsInRect(rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
var attributes: [UICollectionViewLayoutAttributes]? = super.layoutAttributesForElementsInRect(rect)
if let layoutInfo = self.layoutInfo {
attributes!.append(layoutInfo)
}
return attributes
}
так форсированного разворачивания может принять его. Но это может быть не так хорошо?
Вы пытались изменить, чтобы позволить? Он все еще компилируется? – Icaro
Привет @Icaro Мне нужно добавить my layoutInfo, поэтому мне действительно нужен var – dopcn
Так что это должно быть ошибка в компиляторе! – Icaro