"User" 类型的值没有成员“logStatus”Swift 错误
Value of type "User" has no member 'logStatus" Swift Error
我是代码新手,正在尝试学习结构。我创建了一个结构,想知道哪里出错了,因为它不允许我调用我创建的方法 logStatus。
let name: String
var email: String
var followers: Int
var isActive: Bool
init(name: String, email: String, followers: Int, isActive:Bool) {
self.name = name
self.email = email
self.followers = followers
self.isActive = isActive
func logStatus(){
if (isActive) {
print("\(name) is working hard" ) }
else {
print("\(name) has left Earth")
}
}
}
}
var test = User(name: "Richard", email: "richard@gmail.com", followers: 0, isActive: false)
test.logStatus()
您应该从初始化程序中取出 logStatus()
struct SomeStruct {
let name: String
var email: String
var followers: Int
var isActive: Bool
init(name: String, email: String, followers: Int, isActive:Bool) {
self.name = name
self.email = email
self.followers = followers
self.isActive = isActive
}
func logStatus() {
if (isActive) {
print("\(name) is working hard" )
} else {
print("\(name) has left Earth")
}
}
}
我是代码新手,正在尝试学习结构。我创建了一个结构,想知道哪里出错了,因为它不允许我调用我创建的方法 logStatus。
let name: String
var email: String
var followers: Int
var isActive: Bool
init(name: String, email: String, followers: Int, isActive:Bool) {
self.name = name
self.email = email
self.followers = followers
self.isActive = isActive
func logStatus(){
if (isActive) {
print("\(name) is working hard" ) }
else {
print("\(name) has left Earth")
}
}
}
}
var test = User(name: "Richard", email: "richard@gmail.com", followers: 0, isActive: false)
test.logStatus()
您应该从初始化程序中取出 logStatus()
struct SomeStruct {
let name: String
var email: String
var followers: Int
var isActive: Bool
init(name: String, email: String, followers: Int, isActive:Bool) {
self.name = name
self.email = email
self.followers = followers
self.isActive = isActive
}
func logStatus() {
if (isActive) {
print("\(name) is working hard" )
} else {
print("\(name) has left Earth")
}
}
}