gpt4 book ai didi

ios - 我一直遇到错误实例成员 'object' 不能用于类型 ___

转载 作者:行者123 更新时间:2023-11-28 08:50:05 25 4
gpt4 key购买 nike

我正在处理我的 Udacity Nanodegree iOS 项目,它要求我们使用 AppDelegate 的共享模型。我的代码中出现此错误已经有一段时间了,我已经在互联网上寻找解决方案。我尝试使用 get only 声明,但仍然出现此错误...有什么建议吗?这是我的 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
}

最佳答案

您是否正在尝试创建/使用计算属性!?这应该是这样的:

var appDelegate : AppDelegate {
return object as! AppDelegate
}

关于ios - 我一直遇到错误实例成员 'object' 不能用于类型 ___,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34459290/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com