我有一个结构Student
,它包含另一个结构Address
:
public struct Student {
public struct Address {
public static let street = "xyz"
}
}
在学生的单元测试中,我尝试通过以下方式访问街道:
switch(someStr) {
case is Student.Address.street:
...
}
我收到编译错误:Static let 'street' is not a member type of 'Student.Address'
为什么?如何通过street
访问Student
呢?
(此问题仅在单元测试中。)
答案 0 :(得分:2)
您尚未在街道变量中定义其类型var
或let
。
检查以下内容:
public struct Student {
public struct Address {
public static let street = "xyz"
}
}
let street = Student.Address.street
switch(street) {
case Student.Address.street:
print("vishal")
break
default:
break
}
答案 1 :(得分:0)
您错过了let
:
public struct Student {
public struct Address {
public static let street = "xyz"
}
}