如何打印单例变量?

时间:2018-03-24 00:55:52

标签: swift

import UIKit

class User: NSObject {

    static let user = User()
    private override init() {}

    var id: String?
    var name: String?
    var email: String?
    var profileImageUrl: String?
    var profileImage: UIImage?
    var profileImageDownloadUrl: String?
    var partyStatus: Bool?

}

在我的第一个视图控制器中,我做了:

override func viewDidLoad() {
    super.viewDidLoad()

    let user = User.user
    user.name = "Bob"
}

在我的第二个视图控制器中,我做了:

override func viewDidLoad() {
    super.viewDidLoad()

    let user = User.user
    print(user.name)
}

我认为第二个viewcontroller应该打印“Bob”,但它返回为nil。我做错了什么?

0 个答案:

没有答案