Declaring Global Variables in Swift

后端 未结 4 615
我寻月下人不归
我寻月下人不归 2020-12-09 16:06

I want to make a global array of custom objects that can be accessed throughout the app (AppDelegate, ViewController classes, TableViewController classes, etc). I have resea

4条回答
  •  悲哀的现实
    2020-12-09 16:20

    This is how I did it...

    class MessageViewCell {
        struct MessageViewCellHeightCache {
            static var cache: [String:CGFloat] = Dictionary()
        }
    }
    

    And I accessed it as follows:

    MessageViewCell.MessageViewCellHeightCache.cache["first"] = 12.0
    

提交回复
热议问题