2015-09-06 111 views
0

我在這個問題上摸不着頭腦。無法從Swift的collectionview中訪問核心數據對象

我不斷收到以下errror:

'NSInvalidArgumentException', reason: '-[_NSFaultingMutableSet objectAtIndex:]: unrecognized selector sent to instance 

0x7ff3ec6b4590'

當我嘗試從我的集合視圖中訪問照片核心數據模型。

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { 
     var cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! PinViewCollectionViewCell 

     println(selectedPin!.attachedPhotos.count) // Returns 3 
     println(selectedPin!.attachedPhotos[indexPath.row]) 
//^^Returns NSInvalidArgumentException', reason: '-[_NSFaultingMutableSet objectAtIndex:]: 
//unrecognized selector sent to instance 0x7ff3ec6b4590' 

      return cell 

任何想法如何我可以訪問附加的照片個別項目?

+1

最有可能的'attachPhotos'是一個'(NS)集'而不是一個數組。 –

回答

1

試試這個;

println((selectedPin!.attachedPhotos.allObjects as! NSArray)[indexPath.row]); 
+0

這工作作爲附加照片是NS設置,但能夠將其轉換爲使用上述快速原生。作爲[照片] –