猿问

(xiaobai)调用静态属性报错

struct student {

    var stuName = " "

    static var banji = "ios"

}


var xiaoming = student()

xiaoming.stuName = "xiaoming"

println(xiaoming.banji)

小白还在看语法照着书试了一下println 静态属性为什么报错 student doesn't have a member named "banji"

Codingbird
浏览 1645回答 3
3回答

gix_ic

两个问题 首先 student 应该首字母大写 Student, 第二对于类或者结构体的静态属性应该直接用类名或者结构体的名称加点号调用 eg: Student.banji 

lybenson

 静态属性,不能通过实例名称访问  使用student.banji访问

RockenRoll

struct student {    var stuName = " "    static var banji = "ios"}这是个结构体啊,不是静态属性
随时随地看视频慕课网APP

相关分类

iOS
我要回答