How is a global variable set to private understood in swift?

前端 未结 1 1365
南笙
南笙 2021-01-25 13:32

I\'m working through a Core Data exercise from a book and it starts out creating a helper class which is a singleton. I understand that global variables can be created outside

相关标签:
1条回答
  • 2021-01-25 14:06

    A private global variable in Swift is a global that is only accessible from the file in which it is declared.

    The book you are using isn't following current best-practice as far as creating singletons in Swift (perhaps it is a little out-dated?).

    There is no need for the private global variable. You can just say:

    class CDHelper: NSObject {
    // MARK: - SHARED INSTANCE
        static let shared = CDHelper()
    }
    
    0 讨论(0)
提交回复
热议问题