2017-01-14 5 views
2

Ich benutze CustomCollectionViewLayout von https://github.com/brightec/CustomCollectionViewLayout.Konvertierung Swift2 -> Swift3: Fehler mit Any

Nach der Konvertierung von Swift2 nach Swift3 treten zwei Fehler bezüglich Any auf.

Error1:

override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? { 
    return self.itemAttributes[indexPath.section][indexPath.row] as! UICollectionViewLayoutAttributes 
} 

Nachricht Fehler:

CustomCollectionViewLayout.swift:115:54: Type 'Any' has no subscript members

Fehler 2:

override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? { 
    var attributes = [UICollectionViewLayoutAttributes]() 
    if self.itemAttributes != nil { 
     for section in self.itemAttributes { 

      let filteredArray = (section as AnyObject).filtered(

       using: NSPredicate(block: { (evaluatedObject, bindings) -> Bool in 
        return rect.intersects(evaluatedObject.frame) 
       }) 
       ) as! [UICollectionViewLayoutAttributes] 


      attributes.append(contentsOf: filteredArray) 

     } 
    } 

    return attributes 
} 

Fehlermeldung:

Value of type 'Any?' has no member 'frame'

Haben Sie Ideen, wie Sie die Probleme mit Any/AnyObject beheben können?

+0

ich auch gleiche Frage, die sich am –

Antwort

0

Ich löste die Fehler, ersetzen Sie beide Methoden unter denen

override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? { 
     //return self.itemAttributes[indexPath.section][indexPath.row] as! UICollectionViewLayoutAttributes 
     let arr = self.itemAttributes[indexPath.section] as! NSMutableArray 
     return arr[indexPath.row] as! UICollectionViewLayoutAttributes 
    } 


override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? { 
     var attributes = [UICollectionViewLayoutAttributes]() 
     if self.itemAttributes != nil { 
      for section in self.itemAttributes { 

       let filteredArray = (section as! NSMutableArray).filtered(

        using: NSPredicate(block: { (evaluatedObject , bindings) -> Bool in 
         let a = evaluatedObject as! UICollectionViewLayoutAttributes 
         return rect.intersects(a.frame) 
        }) 
        ) as! [UICollectionViewLayoutAttributes] 


       attributes.append(contentsOf: filteredArray) 

      } 
     } 

     return attributes 
    } 
Verwandte Themen