() -> ClassName'没有名为 'memberName' 的成员”是什么意思?-6ren"> () -> ClassName'没有名为 'memberName' 的成员”是什么意思?-这个问题已经有答案了: How to initialize properties that depend on each other (4 个回答) 已关闭 7 年前。 我想编写一个具有 2 个计算属-6ren">
gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 10:12:37 26 4
gpt4 key购买 nike

我想编写一个具有 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/

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