- Swift part3
698 :デフォルトの名無しさん[sage]:2014/10/21(火) 09:08:58.78 ID:KtwB32hV - class A {
// stored variable のクラス変数は未サポート // class var a = 1 // Class variables not yet supported // class let b = 2 // Class variables not yet supported // computed variable ならクラス変数使える class var c: Int { return 3 } private struct StaticVal { // 構造体なら stored variable でも static variable が使える static var val = 4 } // computed クラス変数からプライベートなインナー構造体の static 変数にアクセスすることで // 擬似的に stored クラス変数を実現できる class var d: Int { get { return StaticVal.val } set { StaticVal.val = newValue } } } println(A.c) // 3 println(A.d) // 4 A.d = 99 println(A.d) // 99
|