我正在我的Udacity Nanodegree iOS項目上工作,它要求我們使用與AppDelegate共享模型。我一直在我的代碼中遇到這個錯誤,因爲我已經找到了解決方案。我嘗試使用獲取唯一的聲明,我仍然拋出這個錯誤...任何建議? 這裏是我的CollectionViewController.swift的一部分:我一直有錯誤實例成員'對象'不能用於類型___
import Foundation
import UIKit
class SentMemesCollectionVC:UICollectionViewController{
@IBOutlet weak var imageView: UIImageView!
let object = UIApplication.sharedApplication().delegate
var appDelegate = AppDelegate() {
return object as! AppDelegate //Error get only property //error instance member 'object' cannot be used on type ___
}
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return appDelegate.memes.count
}
let memes = appDelegate.memes
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("CustomMemeCell", forIndexPath: indexPath) as! CustomMemeCell
let meme = memes[indexPath.item]
cell.setText(meme.top, bottomString: meme.bottom)
let imageView = UIImageView(image: meme.image)
cell.backgroundView = imageView
return cell
}
爲什麼你不使用'let object = UIApplication.sharedApplication()。delegate'和'return object.memes.count'? –