我正在使用此Custom Collection View Layout實現。我能夠運行在回購的例子就好了,但是當我複製CustomCollectionViewLayout.swift
到我自己的項目,我得到的方法Type 'Int' does not conform to protocol 'NSCopying'
錯誤類型'Int'不符合協議'NSCopying'
override func layoutAttributesForItemAtIndexPath(indexPath: NSIndexPath) -> UICollectionViewLayoutAttributes? {
return self.itemAttributes[indexPath.section][indexPath.row] as? UICollectionViewLayoutAttributes
}
其中var itemAttributes
是NSMutableArray!
的第二個索引[indexPath.row]
正在產生錯誤。
任何想法?我試過在快速操場上放置相同的功能,並沒有得到任何錯誤..
更新! This是一個swiftstub瓦特/我的操場保存在它。它不會因爲Import UIKit
的執行,但如下:
let x = collectionViewLayout.itemAttributes[indexPath.section]
let y = collectionViewLayout.itemAttributes[indexPath.section][indexPath.row]
print("x's type = \(_stdlib_getDemangledTypeName(x))")
print("x = \(x)")
print("y's type = \(_stdlib_getDemangledTypeName(y))")
print("y = \(y)")
產量:
x's type = __NSArrayM
x = (
"<UICollectionViewLayoutAttributes: 0x7fbe6ac041d0> index path: (<NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0}); frame = (0 0; 66 30); zIndex = 1024; ",
"<UICollectionViewLayoutAttributes: 0x7fbe6ac05030> index path: (<NSIndexPath: 0xc000000000200016> {length = 2, path = 0 - 1}); frame = (65 0; 63 30); zIndex = 1023; ",
"<UICollectionViewLayoutAttributes: 0x7fbe6ae1e2a0> index path: (<NSIndexPath: 0xc000000000400016> {length = 2, path = 0 - 2}); frame = (127 0; 65 30); zIndex = 1023; ",
"<UICollectionViewLayoutAttributes: 0x7fbe6ac06830> index path: (<NSIndexPath: 0xc000000000600016> {length = 2, path = 0 - 3}); frame = (191 0; 66 30); zIndex = 1023; ",
"<UICollectionViewLayoutAttributes: 0x7fbe6ae21e50> index path: (<NSIndexPath: 0xc000000000800016> {length = 2, path = 0 - 4}); frame = (256 0; 67 30); zIndex = 1023; ",
"<UICollectionViewLayoutAttributes: 0x7fbe6ad70f30> index path: (<NSIndexPath: 0xc000000000a00016> {length = 2, path = 0 - 5}); frame = (322 0; 66 30); zIndex = 1023; ",
"<UICollectionViewLayoutAttributes: 0x7fbe6ac054e0> index path: (<NSIndexPath: 0xc000000000c00016> {length = 2, path = 0 - 6}); frame = (387 0; 66 30); zIndex = 1023; ",
"<UICollectionViewLayoutAttributes: 0x7fbe6ad72420> index path: (<NSIndexPath: 0xc000000000e00016> {length = 2, path = 0 - 7}); frame = (452 0; 65 30); zIndex = 1023; "
)
y's type = Swift.ImplicitlyUnwrappedOptional<Swift.AnyObject>
y = <UICollectionViewLayoutAttributes: 0x7fbe6ac041d0> index path: (<NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0}); frame = (0 0; 66 30); zIndex = 1024;
如果將'self.itemAttributes [indexPath.section]'保存到變量中,Swift認爲它的類型是什麼? –
@PhillipMills我更新了我的問題。這不是奇怪,這是在一個操場上的作品,但不會在我的編輯器編譯? – sawyer
您正在使用哪種版本的XCode? – codecowboy