swift - 错误“"' ClassName -> () -> ClassName'没有名为 'memberName' 的成员”是什么意思?

标签 swift

我想编写一个具有 2 个计算属性的类,其中第二个属性引用第一个属性。我试过这个:

class GraphView: UIView {
    var graphVisibleSize: CGSize {
        return CGSize(
            width:  self.bounds.size.width  / 40,
            height: self.bounds.size.height / 40)
    }
    var graphRect = CGRect {
        return CGRect(
            center: CGPointZero,
            size: self.graphVisibleSize)
    }
}

但是,这会导致错误。 Xcode 在 size: self.graphVisibleSize 上给出错误行并说:

'GraphView -> () -> GraphView' does not have a member named 'graphVisibleSize'

这是什么意思?具体来说:

  1. GraphView -> () -> GraphView 是什么意思?部分意思是?

  2. 为什么看不到graphVisibleSize就在它上面的成员?

  3. 额外问题:我尝试在测试类中复制此内容,最终编写了一个运行良好的类 - 但我不明白有什么不同!这是我作为测试而编写的:

    func mungeString(str: String) -> String {
        var newString = "--asdf--\(str)--qwer--"
        return newString
    }
    
    class TestClass: UIView {
        var baseA: String = "This is a string"
        var baseB: String {
            return "This is a computed string"
        }
        var changedA: String {
            return self.baseA.lowercaseString
        }
        var changedB: String {
            return mungeString(self.baseB)
        }
    }
    

    为什么这段代码工作正常,但原始代码却出现错误?

最佳答案

问题是由这一行引起的

var graphRect = CGRect {

应该是

var graphRect: CGRect {

像其他var一样

关于swift - 错误“"' ClassName -> () -> ClassName'没有名为 'memberName' 的成员”是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32131795/

相关文章:

ios - 背景视频快速移动到NavagationBar下

SwiftUI .rotationEffect() 框架和偏移

ios - 快速导航和多种 View

swift - 如何获得Realm中最具代表性的值(value)?

ios - 如何使用 UISplitViewController iOS 在 iPad 上强制以纵向模式显示 MasterViewController

swift - 使用 `Vstack` 将图像调整为屏幕宽度,同时保持纵横比

swift - 向 iOS 应用程序添加声音

swift - Realm 。从 ListBase 中删除对象

ios - -[UIView initWithFrame :] returning nil

ios - 自定义 tableViewCell 中的 NSTimer