-1
,當我在我的項目運行這個方法,「名稱」變量是空斯威夫特函數算法
例子:
import UIKit
class userDetail {
static var name : String?
}
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func OK(sender: UIButton){
getUserDetail()
print(userDetail.name)
// The first click is nil, the second click is print "test". How can I solve this problem?
}
func getUserDetail() {
userDetail.name = "test"
}
}
你在哪裏實例化userDetail? – Desdenova
你能否請至少讓你的代碼編譯? – FreeNickname
@Desdenova我想知道同樣的事情。 'userDetail'是一個類而不是一個變量。 'name'是該類的靜態屬性。 –