【发布时间】:2018-06-18 23:37:19
【问题描述】:
我有下面的代码,但即使将函数 newMethod(newName: String) 添加到类中,username 的值对于变量 user 也不会改变。 Profile 结构在不同的类中定义。我究竟做错了什么?注意:我使用的是 LBTAComponents pod。
import LBTAComponents
class ProfileDatasource: Datasource {
let placeholderIV: UIImageView = {
let imageView = UIImageView()
return imageView
}()
var user = Profile(username: String(), school: "fat", rating: 48, friends: 73, posts: 98, docs: 3, bioText: "Hi I'm a sophomore from Cyprus Bay and can help with most fields relating to high school math.", profileImage: UIImageView(), bgImage: UIImageView())
func newThing(newName: String) {
let newName = "Hi"
print(newName)
ProfileDatasource().user.username = newName
}
}
【问题讨论】:
-
请注意,您的
newName局部变量隐藏了您的newName参数。 -
不相关但将
String()替换为""。